3 Replies Latest reply on Oct 19, 2016 3:08 PM by tmcmanus

    PI Web API - url examples


      Hi all,


      I am currently in the process of rewriting an old piece of code which uses the PI SDK and replacing it with PI WebAPI calls.

      What I am missing is some examples of url's. The help section of the PI WebAPI lists possibilities but has not that many examples.


      For example I want to retrieve a recorded value at a certain timestamp. If the recorded value is not available I want the previous value returned.

      With the PI SDK this is done with the ArcValue and then you can define things like Before or AtOrBefore.

      I get the idea this is possible with the WebAPI too, but how? There is a retrieval-mode defined in the helpfile of the WebAPI.


      Any help is appreciated.





        • Re: PI Web API - url examples
          Roger Palmen

          To get started you could go to the WebAPI URL and browse through the AFmodel. The URL in your browser shows you the call to make.

          That leaves the issue of the WebID. They should be faily constant if your AFmodel stays the same, but you would need some process to first derive WebID's from your AF attributes before making the calls to get the data.


          A slightly better source of documentation over the helpfile is to be found here: https://techsupport.osisoft.com/Documentation/PI-Web-API/help/getting-started.html

            • Re: PI Web API - url examples

              Hi Roger, thanks for thinking with me.

              The url you gave contains the same information as the PI WebAPI helpfile, which you get when the PI WebAPI is installed.

              There are only bits of explanation in the helpfiles of how it works. But no exact directions for example for the case I described.

              Most of the examples go in to detail of how to get elements from AF. What I want to do is get data from PI points and the examples are limited or I did not find them yet.

            • Re: PI Web API - url examples

              Hi Arco,


              We have a lot of great information here on PI Square that should be able to help - this post here is sort of an index of a lot of this information: PI Web API Useful Links Nexus 

              In there you'll find a few "getting started" guides, as well as code samples, and some larger scale example projects


              I'd additional recommend working through our free Programming in PI Web API course here on PI Square, although, admittedly, it does focus more on retrieving data from AF than direct from a PI Data Archive.


              Now, to more specifically answer your question I'd recommend checking out this guide: PI Web API: Quick Start 


              In the section titled "Example: Make a Request" you'll see a specific example about getting the value directly from a PI tag by using the Stream endpoints. You'll see that the GetValue method is called by using the .../Value  URL endpoint once you've identified the PI tag's WebID




              1) Query the stream and capture the WebID in the JSON response:




              2) Use the WebID to return the value:



              2 of 2 people found this helpful