5 Replies Latest reply on May 3, 2016 12:35 PM by gregor

    How to export tag system data using Pi Web API  ?

    AniketAmrutkar

      How to export tag system data using Pi Web API

        • Re: How to export tag system data using Pi Web API  ?
          Marcos Vainer Loeff

          Hello Aniket,

           

          My understanding is that you want to get the historical values, right?

           

          In this case, this is one possible strategy:

           

          1) Make a GET request to: https://marc-web-sql.marc.net/piwebapi/dataservers?name=marc-pi2014

           

           

          {
            "WebId": "s0IQnVxJzj6UuohiErVnqUqgTUFSQy1QSTIwMTQ",
            "Id": "c4d50921-e39c-4be9-a886-212b567a94aa",
            "Name": "marc-pi2014",
            "IsConnected": true,
            "ServerVersion": "3.4.395.64",
            "Links": {
            "Self": "https://marc-web-sql.marc.net/piwebapi/dataservers/s0IQnVxJzj6UuohiErVnqUqgTUFSQy1QSTIwMTQ",
            "Points": "https://marc-web-sql.marc.net/piwebapi/dataservers/s0IQnVxJzj6UuohiErVnqUqgTUFSQy1QSTIwMTQ/points",
            "EnumerationSets": "https://marc-web-sql.marc.net/piwebapi/dataservers/s0IQnVxJzj6UuohiErVnqUqgTUFSQy1QSTIwMTQ/enumerationsets"
            }
          }
          

           

          2) The JSON response will have the link (response.Links.Points) for getting all PI Points information from the selected PI Data Archive. Make another GET request to this link. In my case, it is: https://marc-web-sql.marc.net/piwebapi/dataservers/s0IQnVxJzj6UuohiErVnqUqgTUFSQy1QSTIwMTQ/points. The response would be:

           

          
          {
            "Links": {},
            "Items": [
              {
                "WebId": "P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD",
                "Id": 4051,
                "Name": "04795fc4-ee49-4b6b-b7bc-8b871ecdcebc",
                "PointClass": "base",
                "PointType": "String",
                "Future": false,
                "Links": {
                  "Self": "https://marc-web-sql.marc.net/piwebapi/points/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD",
                  "DataServer": "https://marc-web-sql.marc.net/piwebapi/dataservers/s0IQnVxJzj6UuohiErVnqUqgTUFSQy1QSTIwMTQ",
                  "Attributes": "https://marc-web-sql.marc.net/piwebapi/points/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD/attributes",
                  "Value": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD/value",
                  "InterpolatedData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD/interpolated",
                  "RecordedData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD/recorded",
                  "PlotData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD/plot",
                  "SummaryData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD/summary",
                  "EndValue": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg0w8AAATUFSQy1QSTIwMTRcMDQ3OTVGQzQtRUU0OS00QjZCLUI3QkMtOEI4NzFFQ0RDRUJD/end"
                }
              },
              {
                "WebId": "P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0",
                "Id": 4054,
                "Name": "04b1504f-38ac-43bf-acbc-9299404e8004",
                "PointClass": "base",
                "PointType": "String",
                "Future": false,
                "Links": {
                  "Self": "https://marc-web-sql.marc.net/piwebapi/points/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0",
                  "DataServer": "https://marc-web-sql.marc.net/piwebapi/dataservers/s0IQnVxJzj6UuohiErVnqUqgTUFSQy1QSTIwMTQ",
                  "Attributes": "https://marc-web-sql.marc.net/piwebapi/points/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0/attributes",
                  "Value": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0/value",
                  "InterpolatedData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0/interpolated",
                  "RecordedData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0/recorded",
                  "PlotData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0/plot",
                  "SummaryData": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0/summary",
                  "EndValue": "https://marc-web-sql.marc.net/piwebapi/streams/P0IQnVxJzj6UuohiErVnqUqg1g8AAATUFSQy1QSTIwMTRcMDRCMTUwNEYtMzhBQy00M0JGLUFDQkMtOTI5OTQwNEU4MDA0/end"
                }
              }
          ]
          }
          

           

           

          3)Note that the Items property in an array with many objects, each one contains information about a PI Point, its WebId (Items[i].WebId) and a link to get its recorded values (Items[i].Links.RecordedData). Finally, you need to make a GET request for each one of the PI Point whose data you want to export. You can change the query string of this url in order to set up the start time and end time properly.

           

          In order to improve the performance, consider using BATCH,  make requests in bulk (GET streamsets/recorded) using the WebId of the previous response. You can use both techniques if you prefer.

           

          Here you have some information about making BATCH requests in C#.

           

          Finally, according to the size of your PI Data Archive, this operation can take a lot of time. You might want to use PI AF SDK instead in order to improve the performance.

           

          These are some general guidelines. Please let me know if you still have any question.

          2 of 2 people found this helpful
          • Re: How to export tag system data using Pi Web API  ?
            AniketAmrutkar

            Hello Marcos,

             

            Thanks for the response.

            I will work on it programmatically.

            I am having one more question. How do we know that the Pi Tag which I am fetching using API, is belongs to which Equipment ?

             

            So I am getting in response something like this :

             

            Request : <host>piwebapi/streamsets/recorded?webid=P0r0HMDky5PUGJ-ic7-u7dlgAQAAAAREVWLVdJTjEyXFNJTlVTT0lE&webid=P0r0HMDky5PUGJ-ic7-u7dlgCAAAAAREVWLVdJTjEyXEJBOkNPTkMuMQ

             

            Response :

            {

              "Links": {},

              "Items": [

                {

                  "WebId": "P0r0HMDky5PUGJ-ic7-u7dlgCAAAAAREVWLVdJTjEyXEJBOkNPTkMuMQ",

                  "Name": "BA:CONC.1",

                  "Links": {

                    "Source": "https://40.86.90.6/piwebapi/points/P0r0HMDky5PUGJ-ic7-u7dlgCAAAAAREVWLVdJTjEyXEJBOkNPTkMuMQ"

                  },

                  "Items": [

                    {

                      "Timestamp": "2016-05-02T09:08:48Z",

                      "Value": 15.2593546,

                      "UnitsAbbreviation": "",

                      "Good": true,

                      "Questionable": false,

                      "Substituted": false

                    },

                    {

                      "Timestamp": "2016-05-02T09:09:48Z",

                      "Value": 16.1898136,

                      "UnitsAbbreviation": "",

                      "Good": true,

                      "Questionable": false,

                      "Substituted": false

                    }

                  ],

                  "UnitsAbbreviation": ""

                },

                {

                  "WebId": "P0r0HMDky5PUGJ-ic7-u7dlgAQAAAAREVWLVdJTjEyXFNJTlVTT0lE",

                  "Name": "SINUSOID",

                  "Links": {

                    "Source": "https://40.86.90.6/piwebapi/points/P0r0HMDky5PUGJ-ic7-u7dlgAQAAAAREVWLVdJTjEyXFNJTlVTT0lE"

                  },

                  "Items": [

                    {

                      "Timestamp": "2016-05-02T09:31:18Z",

                      "Value": 1.853565,

                      "UnitsAbbreviation": "",

                      "Good": true,

                      "Questionable": false,

                      "Substituted": false

                    },

                    {

                      "Timestamp": "2016-05-02T10:40:48Z",

                      "Value": 18.1286125,

                      "UnitsAbbreviation": "",

                      "Good": true,

                      "Questionable": false,

                      "Substituted": false

                    }

                  ],

                  "UnitsAbbreviation": ""

                }

              ]

            }

             

            How can I find the actual physical equipmentID this Result Belongs to ?