4 Replies Latest reply on Jan 8, 2018 3:31 AM by Dan Fishman

    PI Web API Filter Expression

    mdsterman

      I am using C# to write piWebAPI calls.  The query results are shown below . Would someone please provide a filter expression string to remove all results with Value.Value < 5?

       

      Thank You,

       

      Marty 

       

      "Items": [

          {

            "Timestamp": "2017-02-01T12:49:36Z",

            "Value": {

              "Name": "Closed-1",

             "Value": 1,

      "IsSystem": false

            },

      "UnitsAbbreviation": "",

            "Good": true,

      "Questionable": false,

      "Substituted": false

          },

          {

            "Timestamp": "2017-02-01T20:26:31Z",

            "Value": {

              "Name": "Closed-1",

              "Value": 1,

      "IsSystem": false

            },

      "UnitsAbbreviation": "",

            "Good": true,

      "Questionable": false,

      "Substituted": false

          }

      }

        • Re: PI Web API Filter Expression
          John Messinger

          So do you want the filter to be applied at the time the web API call is made, or after you have received the response from your call? You haven't mentioned what controller method you are using to get the results shown above, so it may be safe to assume that you are simply using the streams GetRecorded method. If you want to apply the filter at the time of the web API call, then look at using the GetAtRecorded method of the Calculation controller - this method allows you to pass in a standard Performance Equation expression which would apply your filter.

           

          Alternatively, if you don't want to change the web API method you are currently using to retrieve your data, the I would apply a LINQ query to the results set that is returned from the web method call.

          2 of 2 people found this helpful
          • Re: PI Web API Filter Expression
            rschmitz

            Hi Martin,

             

            For things on the simplier side like this I would recommend using a filterExpression in conjunction with a GetRecorded call by the stream controller.

            So for example:

            <BASE URL>/piwebapi/streams/{WebId}/recorded?filterexpression='CDT158'>178

             

            This will only return values for the specified WebId when the CDT158 is greater than 178. In your case the WebId would be the same as the tag listed in the filter expression since you want the tag being returned to be filtered by it's own values.

             

            Cheers,

            Rob

            2 of 2 people found this helpful