17 Replies Latest reply on May 18, 2018 5:05 AM by RollyD

    PI Web API query examples

    gmoffett

      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

      https://localhost/piwebapi/elements?path=\\EME\Power\Atlanta%20Data%20Center\Server%20Rack1\ION%206200%20Power%20Meter1

       

      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

         }

      }