PI Web API query examples

g'day,

 

Over time have received and seen requests for "just a few example queries" to get folks on their way with the PI Web API.

 

To add to the existing blog posts that provide coded examples in various languages below are a few examples that appear to have been useful.

 

Cheers,

 

The examples were created using an AF database called Power that you can download including assets and thanks to the power of AF templates automatically (check create or update Pi Points on import) creates tags associated with the - installed by default - random interface that will generate time series data.

 

How do I get a WebId to an object and links to the various methods I can request?

a. You can navigate from the piwebapi root and follow the links returned in a browser e.g.:https://localhost/piwebapi/

b. Search for a known object, for example a power meter element

 

How do I get the current values for all attributes of the power meter?

https://localhost/piwebapi/streamsets/E0e5R4zUACHUOxUKQtNYteqg5pBaQDDa5BGAxAAd2Lck3QRU1FXFBPV0VSXEFUTEFOVEEgREFUQSBDRU5U…

 

How about filtering based on the attribute name to select only attributes that for example start with the letter i and return the current value for each one?

https://localhost/piwebapi/streamsets/E0e5R4zUACHUOxUKQtNYteqg5pBaQDDa5BGAxAAd2Lck3QRU1FXFBPV0VSXEFUTEFOVEEgREFUQSBDRU5U…

 

How do I get all the values for all attributes of an element for 30 minute period starting an hour ago?

https://localhost/piwebapi/streamsets/E0e5R4zUACHUOxUKQtNYteqg5pBaQDDa5BGAxAAd2Lck3QRU1FXFBPV0VSXEFUTEFOVEEgREFUQSBDRU5U…

 

If not already familiar with query strings, from these examples you can get the idea about URL parameters or query string with the first one prefixed by a ? and subsequent parameters with &

 

How do I post a value to an attribute?

Using a POST HTTP request method

https://eme/piwebapi/streams/A0Ee5R4zUACHUOxUKQtNYteqg5pBaQDDa5BGAxAAd2Lck3Quk4fLKyau1I2c-yNMMsxvgRU1FXFBPV0VSXEFUTEFOVE…

With the message body containing:

{

  "Timestamp": "2015-04-03T18:46:10.39135 -7",

  "Value": 42.0,

}

 

See also the online documentation https://localhost/piwebapi/help (also available as a downloadable zip file)  for streamsets that allows posting values to multiple streams

 

How do I post a digital state to indicate a problem with data collection?

Example of writing a system digital state value via Web API POST body below, note the value # corresponds to the entry in PI System Management Tools > Points > Digital States.

Another way to represent the missing data could be using the digital state: No data which has a value of 248

As per the previous example specify the stream you want to update in the URL of a HTTP POST request to the PI Web API and include a message body for example:

{

   Value: {

          Name: "Comm Fail",

          Value: 313,

         IsSystem: true

   }

}

Parents
  • Hi

    Is there a way to query only the PI data archive and get multiple tags and their values in one call?

    We don't have everything in AF (I know, I know, we're working on it) and a lot of queries would be something like

    "Give me all the PI tags that start with 0003* and their current values"

    at the moment I do a query like

    and then, with all the tags returned by that, do a new individual call for each to get the current value, now that we have the web ID. but this is a lot of calls (if a search returns 100 tags, it's 101 total calls. whereas I am hoping it could be 1)

    I know this is possible if all the tags are attributes in one element.

    thanks!      

Reply
  • Hi

    Is there a way to query only the PI data archive and get multiple tags and their values in one call?

    We don't have everything in AF (I know, I know, we're working on it) and a lot of queries would be something like

    "Give me all the PI tags that start with 0003* and their current values"

    at the moment I do a query like

    and then, with all the tags returned by that, do a new individual call for each to get the current value, now that we have the web ID. but this is a lot of calls (if a search returns 100 tags, it's 101 total calls. whereas I am hoping it could be 1)

    I know this is possible if all the tags are attributes in one element.

    thanks!      

Children