PI Web API query examples

Discussion created by gmoffett Employee on Apr 4, 2015
Latest reply on Nov 22, 2018 by Ashif Sayyad



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.




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?



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?



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



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


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