In this video we're going to demonstrate request templates with the batch controller.
Request templates allow us to create a set of sub requests with dynamic URLs for multiple
sub requests based on the template. Let's say you need to select multiple JSON path
tokens so if you have an array of elements or attributes and we might need to create
a sub request for each one of those we can use request templates to do this. We'll use
the request template property in our sub request in conjunction with the parent ID
and the parameters fields that we learned about in the previous video. Nested in here
is going to be a resource property which we will fill out in the same manner as we
did before using the string substitution with JSON path selecting the parameter.
However this time the parameters will have an array rather than selecting one object we'll
be selecting them all. Let's get started with an example: in my parent sub request I'm going
to request all of the equipment with the AF template boiler. We can see from the response
that it's returning a number of elements under the content that items object in the response.
In order to select all of these we'll need to use some new JSON path syntax. We'll use
brackets and an asterisk in order to reference all of the objects in that
items array. Now let's make our child sub request. I want to get the current value
for all attributes on any boiler elements so we'll be using the stream sets controller. We
have a get method with the parent ID being our query for boiler elements request.
Next we'll need to use that request template parameter
and encased in the brackets of this is going to be a resource parameter.
This resource will be our URL slash PI Web API slash stream sets slash, here is where our web
ID is going to go, since we'll be retrieving it via the parameters field I'll put in a curly brace
and a zero and lastly since we want the current value we'll finish the URL with slash value.
Again, let's take a look at the response for just the parent request here that I ran earlier.
I made this request specifically so I could see the response and identify the path with
JSON path. It looks like to get the web IDs of these elements I'll need to go under content,
then items and select the web ID property. Our parameters field then ends up looking like so.
We use the asterisk after the items property to let the PI Web API know
that we would like to get the web ID property for all items in the array.
When we send this we expect to see a sub response for each web ID in the array.
Looking at the response we can see it's quite large. It's also returning to us
all of the attributes that were returned in the query for boiler elements sub request.
An important thing to note looking at this response is that each of these sub responses
based on the request template are returned as this content of a single sub response.
Request templates are a powerful tool to help you retrieve all the information
you need very quickly. It's important to keep in mind though you can potentially be
making hundreds or even thousands of sub requests using the template when you're
selecting all of the items in an array, so please be careful when using this tool.