2 Replies Latest reply on Jun 27, 2018 4:48 PM by Roger Palmen

    PI Web API Returns Nested Values

    TamLe

      When querying the PI Web API some values are nested and some aren't for the same attribute but different element. How do you determine when an value is going to be nested to create dynamic calls to determine how to handle the data returned? Here's an example of the data returned where the paths are structured the same.

       

        "Links": {},

        "Items": [

          {

            "WebId": "Plant1WebID",

            "Name": "WindSpeed",

            "Path": "\\\\server\\SoCo\\Generation\\SPC\\Solar\\Plant1|WindSpeed",

            "Links": {

              "Source": "https://spc-pi.southernco.com/piwebapi/attributes/Plant1WebID"

            },

            "Value": {

              "Timestamp": "2018-06-27T12:05:14Z",

              "Value": 0.0,

              "UnitsAbbreviation": "m/s",

              "Good": true,

              "Questionable": false,

              "Substituted": false

            }

          }

       

       

       

       

        "Links": {},

        "Items": [

          {

            "WebId": "Plant2WebID",

            "Name": "WindSpeed",

            "Path": "\\\\server\SoCo\\Generation\\SPC\\Solar\\Plant2|WindSpeed",

            "Links": {

              "Source": "https://spc-pi.southernco.com/piwebapi/attributes/Plant2WebID"

            },

            "Value": {

              "Timestamp": "2017-04-12T22:11:38Z",

              "Value": {

                "Name": "Pt Created",

                "Value": 253,

                "IsSystem": true

              },

              "UnitsAbbreviation": "",

              "Good": false,

              "Questionable": false,

              "Substituted": false

            }

          }

        • Re: PI Web API Returns Nested Values
          awoodall

          The PI Web API help located at /piwebapi/help/topics/value-types discusses all the possible formats of return values. In this case it looks like the second attribute is mapped to a tag has a system digital state, which for the PI Web API is considered of enumeration value format. Your JSON library will need to create the equivalent value object based on the JSON data produced for the Value field and then you'll have to have code to differentiate each possible case of value object type to consume it properly.

           

          Here is a copy of the relevant part of the 2017R2 help page that lists all the possible value types for PI data references:

          Good values (values for which the 'Good' property is set to true) are mapped to and from JSON according to the following rules:

          • Boolean: JSON boolean
          • Byte, Double, Int16, Int32, Int64, Single: JSON number
          • DateTime: ISO8601 UTC formatted JSON string
          • Guid: hyphenated hexadecimal digits as a JSON string
          • String: JSON string
          • Array: JSON array of the corresponding type
          • Enumeration value: JSON object with 3 properties: Name (string), Value (number), IsSystem (boolean)

          Bad or error values (values for which the 'Good' property is set to false) may be serialized as one of the above types or, more commonly, as an error represented as a string, enumeration value, or JSON object containing a single property, 'Errors', which is a string array containing one or more error messages.

          The above discussion applies to default PI System behaviors. Custom data references may produce other behavior.

           

           

          1 of 1 people found this helpful
          • Re: PI Web API Returns Nested Values
            Roger Palmen

            In this case, the Good: False gives you the indication the value field is a system state, and you should have specific handling for that.

            In my typical uses (e.g. for visualizations) i use that to e.g. leave out the enumeration value from the results i use, or set it to null to indicate a (valid) data gap.

            1 of 1 people found this helpful