Solution: Batch Controller

Document created by jkim Employee on Jun 24, 2019Last modified by jkim Employee on Jun 24, 2019
Version 2Show Document
  • View in full screen mode

The following should be done using Fiddler, PostMan, or another non-browser application capable of making HTTP requests

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

HTTP Verb: POST

URL: https://HostName/piwebapi/batch

Request Body:

{

  "DataArchives": {

    "Method": "GET",

    "Resource": "https://hostname/piwebapi/dataservers"

  },

  "AssetServers": {

    "Method": "GET",

    "Resource": "https://hostname/piwebapi/assetservers",

    "ParentIds": ["DataArchives"]

  }

}

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

HTTP Verb: POST

URL: https://HostName/piwebapi/batch

Request Body:

 

{

  "GetDataArchiveWebIdByPath": {

    "Method": "GET",

    "Resource": "https://HostName/piwebapi/dataservers?path=\\\\PISRV1"

  },

  "CreateTag": {

    "Method": "POST",

    "Resource": "{0}",

    "ParentIds": ["GetDataArchiveWebIdByPath"],

    "Parameters": ["$.GetDataArchiveWebIdByPath.Content.Links.Points"],

    "Content": "{

      \"Name\": \"New Tag\",

      \"PointClass\": \"Classic\",

      \"PointType\": \"Float32\"

    }"

  }

}

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

HTTP Verb: POST

URL: https://HostName/piwebapi/batch

Request Body:

{

  "GetElementWebIdByPath": {

    "Method": "GET",

    "Resource": "https://HostName/piwebapi/elements?path=\\\\piaf\\NuGreen\\NuGreen\\Wichita\\CrackingProcess\\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\": \"New Attribute\",

      \"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\"

    }"

  }

}

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

HTTP Verb: POST

URL: https://HostName/piwebapi/batch

Request Body:

{

  "GetElementWebIdByPath": {

    "Method": "GET",

    "Resource": "https://Hostname/piwebapi/elements?path=\\\\piaf\\NuGreen\\NuGreen\\Wichita\\CrackingProcess\\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"]

  }

}

Attachments

    Outcomes