9 Replies Latest reply on Mar 15, 2015 6:03 AM by mhalhead

    PI Web API: Query in one Request

    PFC5478

      Hi all,

       

      I think I should have some misconception and I do appreciate if anyone can clarify me.

       

      According to https://techsupport.osisoft.com/Troubleshooting/KB/KB01128 , in section "Sample Request", three queries

      would need to query for getting the Snapshot:

       

      1. Use the Search API to obtain the WebID of the Element.

      2. Use the Element API to obtain the WebID of the Attribute.

      3. Use the Stream API to request the Snapshot Value.

      (Above reference has mentioned Step 2 and Step 3 can be combined to one step by using "response.Items.Links.Value".)

       

      I would like to ask is it possible to make a single query to replace above 3 steps which can get the Snapshot Value, assume the point

      (for PI Server Tag Point) or element (for AF Server Tag) is known in advance? e.g. (Below syntax is wrong. If it is possible, I want to

      know the correct syntax.)

       

      https://<piwebapiserver>/piwebapi/stream/[elements?path=<elementpath>]/value

      or

      (according above reference) https://localhost/piwebapi/streams/[elements?path=\\MYPISERVER\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Fuel Gas Flow]/value

       

      Thank you all for your kind attention.

        • Re: PI Web API: Query in one Request
          Eugene Lee

          Hi Paul,

           

          I don't think that is possible because the assets are identified in the URL by the WebID and not by the point name. So you will have to make some calls beforehand to determine the WebID.

          • Re: PI Web API: Query in one Request
            kfong

            I believe that Eugene is correct.  The sample code is included in that KB you referenced; are those snippets not what you are trying to accomplish?

              • Re: PI Web API: Query in one Request
                PFC5478

                Thanks Eugene and Keith!

                 

                Currently my team have a mobile application calling PI/AF data by PI Web Services and we would like to improve the performance by considering to replace by PI Web API instead.

                 

                Due to limited bandwidth and I/O issue, if the above example can be accomplished by one single query, this would be perfect in our situation. If not, we may consider to write

                a Restful Web Services which encapsulate the PI Web API. Our target is one single mobile query can retrieve the information.

                 

                I acknowledge PI Web API is quite new and is still developing and I am afraid I have overlooked some tricks in existing PI Web API which can fulfill our needs. The document I

                referenced above serves as "Introduction" purpose which illustrate the normal query steps but may not be the best method for development. That's the reason I raised my question here.

                 

                I marked Eugene Lee's reply as Correct Answer since it is the first reply.

                  • Re: PI Web API: Query in one Request
                    Eugene Lee

                    Hi Paul,

                     

                    If bandwidth and speed is your concern, you would also find that it is beneficial to use the newest version of PI Web API (version 2015) which offer things like HTTP Compression and bulk time series data calls against Element or Event Frame streams.

                      • Re: PI Web API: Query in one Request
                        PFC5478

                        Thanks Eugene.

                         

                        I just found a similar question. My understanding is Osisoft do not recommend "Encapsulation" as I mentioned above:

                         

                        Re: Basic question about how to pull data using the RESTFul API

                          • Re: PI Web API: Query in one Request
                            Eugene Lee

                            Hi Paul,

                             

                            Which part of that discussion makes you think that? Is it this "We don't recommend grabbing and storing ID's as the best programmatic access. We recommend using the links item embedded in each JSON object."?

                              • Re: PI Web API: Query in one Request
                                PFC5478

                                Yes. In my early reply I consider "...write a Restful Web Services which encapsulate the PI Web API" to make a single mobile query.

                                Certainly it gives issues in authentication and mimic the WebID. The sentence "We don't recommend grabbing and storing ID's as the best programmatic

                                access. We recommend using the links item embedded in each JSON object." illustrates the standpoint.

                                 

                                You mentioned about the latest PI Web API 2015 release (1.4.1.127) includes bulk call. Certainly it is helpful for query many attributes of a element.

                                Instead of data amount issue, we also consider the number of queries for a simple call (just like getting a single Snapshot Value of a element.)

                                  • Re: PI Web API: Query in one Request
                                    Eugene Lee

                                    Yes, the way that Sean mentions will still require you to get the JSON object beforehand with a query so that you can use the links in the JSON object to get the snapshot value. Therefore, more than one query will still have to be made. If you really need just one query, why don't you consider storing the WebIDs in a dictionary that is mapped to the PIPoint's name and do the resolving in the application itself before making the call to PI Web API. This is provided your data structure in your servers don't change. Just a thought.

                                      • Re: PI Web API: Query in one Request
                                        mhalhead

                                        Hi Eugene,

                                         

                                        The WebId that is returned by PI Web API is an encoding of the path (AF Attribute path or the PI Point path) and the ID (element/attribute ID). From what I've read and worked out PI Web API uses the ID preferentially to retrieve the data; if the id isn't valid it then uses the path (if that is also not valid well you can guess). This makes the webId quite robust so you don't need to retrieve the webId for every data call this would be pretty inefficient. I would therefore cache the Ids; you do need to refresh this cache at regular intervals and that will be determined by you application.

                                         

                                        PI Web API in my experience is a lot faster than the PI Web Services; we are using it for integration into SAP-PM. In our testing we've found that we can reliably retrieve daily running totals (one value per day) for a set of 18 pumps in less than five seconds including the webId calls. And this was across our crummy networks (most people in the USA or Europe have better bandwidth to their houses than our operations).

                                         

                                        The biggest impact to a client's performance will likely be the amount of data you pull. A month of one second data will make the additional WebId calls irrelevant.