Exercise 6: Batch Controller with Fiddler

Document created by Milanez on Jun 4, 2020
Version 1Show Document
  • View in full screen mode

!!! Remember to add the Content-Type: application/json at the header !!!

 

1. Use a batch request to retrieve all the Asset Servers and Data Archives for your PI Web Instance
1.1)     Ensure that the Data Archives are returned prior to the Asset Servers in the response

 

{
  "DataArchives": {
    "Method": "GET",
    "Resource": "https://hostname/piwebapi/dataservers"
  },
  "AssetServers": {
    "Method": "GET",
    "Resource": "https://hostname/piwebapi/assetservers",
    "ParentIds": ["DataArchives"]
  }
}

 

2. Starting with a blank request body, do the following in a single call to the batch controller:
2.1)     Retrieve the WebId of that Data Archive with a GetBy Path call
2.2)     Create a new tag called "New Tag" on the Data Archive using Parameters from the first sub-request

 

{
  "GetDataArchiveWebIdByPath": {
    "Method": "GET",
    "Resource": "https://hostname/piwebapi/dataservers?path=\\\\SERVER"
  },
  "CreateTag": {
    "Method": "POST",
    "Resource": "{0}",
    "ParentIds": ["GetDataArchiveWebIdByPath"],
    "Parameters": ["$.GetDataArchiveWebIdByPath.Content.Links.Points"],
    "Content": "{
      \"Name\": \"New Tag\",
      \"PointClass\": \"Classic\",
      \"PointType\": \"Float32\"
    }"
  }
}

 

3. Starting with a blank request body, do the following in a single call to the batch controller:
3.1)     Retrieve the WebId of the element “\\PIAF\Nugreen\Nugreen\Wichita\Cracking Process\Equipment”
3.2)     create a new element under the Equipment Element called "New Element", using Parameters from the first sub-request
3.3)     create an attribute for the new element linked to the new tag, using parameters from the second sub-request
3.4)     update the value of the attribute to 5450

 

OBS: if you run at the first time and got an error, please check for the element and delete it. After some minutes, you'll be able to create it again.
Also, you can rename the element if it takes too much time. (I think it´s related to the PI WEB PI database scan job).

 

{
    "GetElementWebIdByPath": {
        "Method": "GET",
        "Resource": "https://hostname/piwebapi/elements?path=\\\\SERVER\\NuGreen\\NuGreen\\Wichita\\Cracking Process\\Equipment"
    },
    "CreateElement": {
        "Method": "POST",
        "Resource": "{0}",
        "ParentIds": ["GetElementWebIdByPath"],
        "Parameters": ["$.GetElementWebIdByPath.Content.Links.Elements"],
        "Content": "{\"Name\": \"New Element\" }"
    },
    "CreateAttribute": {
        "Method": "POST",
        "Resource": "{0}/Attributes",
        "ParentIds": ["GetElementWebIdByPath", "CreateElement"],
        "Parameters": ["$.CreateElement.Headers.Location"],
        "Content": "{
            \"Name\": \"Atributo teste\",
            \"Type\": \"Int32\",
            \"DataReferencePlugIn\": \"PI Point\",
            \"ConfigString\":\"New Tag;ReadOnly=false\"
        }"
    },
    "UpdateAttributeValue": {
        "Method": "PUT",
        "Resource": "{0}/Value",
        "ParentIds": ["CreateAttribute"],
        "Parameters": ["$.CreateAttribute.Headers.Location"],
        "Content": "{
            \"Timestamp\": \"*\",
            \"Value\": \"5450\"
        }"
    }
}

 

4. Starting with a blank request body, do the following in a single call to the batch controller:
4.1)     Query for the element "\\PIAF\Nugreen\Nugreen\Wichita\Cracking Process\Equipment\P-723"
4.2)     Query for the attributes on the element
4.3)     Using a request template, retrieve the interpolated data for the attribute
4.4)     Make a second call for the interpolated attribute data using the streamsets by referencing the link from the first call for the element
4.5)     Do you see a difference in the data between the streamsets call and using a request template? (pick any one attribute)

 

{
    "GetElementWebIdByPath": {
        "Method": "GET",
        "Resource": "https://hostname/piwebapi/elements?path=\\\\SERVER\\NuGreen\\NuGreen\\Wichita\\Cracking Process\\Equipment\\P-723",
    },
    "QueryForAttributes": {
        "Method": "GET",
        "Resource": "{0}",
        "ParentIds": ["GetElementWebIdByPath"],
        "Parameters": ["$.GetElementWebIdByPath.Content.Links.Attributes"]
    },
    "QueryForStreams": {
        "Method": "GET",
        "RequestTemplate": {"Resource": "{0}"},
        "ParentIds": ["QueryForAttributes"],
        "Parameters": ["$.QueryForAttributes.Content.Items[*].Links.InterpolatedData"]
    },
    "QueryForStreamSets": {
        "Method": "GET",
        "Resource": "{0}",
        "ParentIds": ["GetElementWebIdByPath"],
        "Parameters": ["$.GetElementWebIdByPath.Content.Links.InterpolatedData"]
    }
}

 

Comparing the two queries for streams:

 

QueryForStreams > Content > Items (15). Each Item with Content > Items where Items are the number of interpolated data. Don't have attribute info, only data.

 

QueryForStreamsSets > Content > Items (15). Each Item have the attribute info and a list of Items with the interpolated data.

Attachments

    Outcomes