8 Replies Latest reply on Apr 14, 2016 1:59 PM by arosenthal

    PI WebAPI Batch CTP question

    arosenthal

      I am trying to write a batch query for the PI WebAPI that gets a specific PI server and then uses the "Points" link to get the PI points in that server. My initial query works fine:

       

      {
       "GetPIServer": {
         "Method": "GET",
         "Resource": "https://localhost/piwebapi/dataservers?path=\\\\DEV_PI"
       },
       "GetPoints": {
         "Method": "GET",
         "Resource": "$.GetPIServer.Content.Links.Points",
         "ParentIds": [
           "GetPIServer"
         ]
       }
      }
      

       

      However, if I want to restrict the number of points it returns by using the "maxCount" parameter, like this:

       

      {
       "GetPIServer": {
         "Method": "GET",
         "Resource": "https://localhost/piwebapi/dataservers?path=\\\\DEV_PI"
       },
       "GetPoints": {
         "Method": "GET",
         "Resource": "$.GetPIServer.Content.Links.Points?maxCount=100",
         "ParentIds": [
           "GetPIServer"
         ]
       }
      }
      

       

      Then I get the following error in the response back:

       

      Invalid resource: $.GetPIServer.Content.Links.Points?maxCount=100

       

      Is there a way to accomplish this using JSONPath? Perhaps a string concatenation operator of some kind...

        • Re: PI WebAPI Batch CTP question
          Jerome Lefebvre

          Hello Aaron,

           

          I believe the issue is that this is not valid JSONpath expression. I couldn't find any good documentation that would clarify this, possibly the following gives the best list of what is available JSONPath - XPath for JSON  .

           

          One way to do the same thing you want is in the second part of batch request is to use an absolute URL along with a parameter. So that you can get the web ID of the Data Server in your first call and then use it in your second.

          "GetPIServer": { 

             "Method": "GET", 

             "Resource": "https://localhost/piwebapi/dataservers?path=\\\\localhost

          }, 

          "GetPoints": { 

             "Method": "GET", 

             "Resource": "https://localhost/piwebapi/dataservers/{0}/points?maxcount=100", 

             "ParentIds": [ 

               "GetPIServer" 

             ],

             "Parameters": [

                 "$.GetPIServer.Content.WebId"

                 ]

          }

           

          This retrieves the same data you were interested in.

           

          Cheers,

          Jerome

          2 of 2 people found this helpful
            • Re: PI WebAPI Batch CTP question
              arosenthal

              Thanks Jerome. The use of parameters is exactly what I was looking for. I modified your answer slightly so that I don't have to keep defining the base URL in each query and it works exactly like I wanted:

               

              {
               "GetPIServer": {
                 "Method": "GET",
                 "Resource": "https://localhost/piwebapi/dataservers?path=\\\\DEV_PI"
               },
               "GetPoints": {
                 "Method": "GET",
                 "Resource": "{0}?maxCount=100",
                 "Parameters": [
                   "$.GetPIServer.Content.Links.Points"
                 ],
                 "ParentIds": [
                   "GetPIServer"
                 ]
               }
              }
              
              • Re: PI WebAPI Batch CTP question
                arosenthal

                Just as a follow-up, I think it would be really powerful if the batch queries allowed the use of recursive operations in the JSONPath. For example, I would like to be able to write a batch query that returns the values of multiple PI points, like this:

                 

                {
                 "GetPIServer": {
                   "Method": "GET",
                   "Resource": "https://localhost/piwebapi/dataservers?path=\\\\DEV_PI"
                 },
                 "GetPoints": {
                   "Method": "GET",
                   "Resource": "{0}?maxCount=100",
                   "Parameters": [
                     "$.GetPIServer.Content.Links.Points"
                   ],
                   "ParentIds": [
                     "GetPIServer"
                   ]
                 },
                 "GetValues": {
                   "Method": "GET",
                   "Resource": "$.GetPoints.Content.Items[*].Links.Value",
                   "ParentIds": [
                     "GetValues"
                   ]
                 }
                }
                

                 

                Unfortunately this currently doesn't work as I received the following error:

                Circular or nonexistent dependency detected. Request not executed.

                Is this something OSIsoft is planning on implementing in the future?

                  • Re: PI WebAPI Batch CTP question
                    Jerome Lefebvre

                    Hello Aaron,

                     

                    The "circular" error is referring to the fact that you have GetValues in the ParentIds list, instead of GetPoints.

                     

                    In PI Web API 2015 R3, the functionality for those types of request was not yet included.

                    Using PI Web API 2016, I was able to write the Batch request you wanted by using the RequestTemplate key and the following syntax:

                     

                    {
                     "GetPIServer": {
                       "Method": "GET",
                       "Resource": "https://localhost/piwebapi/dataservers?path=\\\\localhost"
                     },
                     "GetPoints": {
                       "Method": "GET",
                       "Resource": "{0}?maxCount=3",
                       "Parameters": [
                         "$.GetPIServer.Content.Links.Points"
                       ],
                       "ParentIds": [
                         "GetPIServer"
                       ]
                     },
                     "GetValues": {  
                       "Method": "GET", 
                       "RequestTemplate": {
                            "Resource": "https://localhost/piwebapi/streams/{0}/value"
                       },
                       "Parameters": ["$.GetPoints.Content.Items[*].WebId" ],
                       "ParentIds": [  
                         "GetPoints"  
                       ]
                     }
                    }
                    

                     

                    Cheers,

                    Jerome

                • Re: PI WebAPI Batch CTP question
                  Eugene Lee

                  Hi Aaron,

                   

                  The issue is that JSONPath doesn't support concatenation as I found here.

                  Support for Concatenation [#1096682] | Drupal.org

                  2 of 2 people found this helpful