This video will walk through the solutions to exercise 2 step by
step. The goal of this exercise is to practice using URL parameters to
supply additional fields and change the response that we get from PI Web API.
Our first task is to use the element controllers GetByPath method to retrieve
the AF element f110. Going to the documentation for this end point we can see that it takes a
URL parameter for the path along with some other optional parameters. We specify URL
parameters by adding a question mark after the endpoint and then a name value pair,
so in this case we will put path equals and then place our path.
In the request/response we see that our desired element was returned.
Notice that one of these fields is the web ID which uniquely identifies
this element within PI Web API. Web IDs will be discussed in detail in lesson 5.
If we click on the self link we can see that the Web API returns the same
element using the web ID and the element controller's get method. Next we're going
to retrieve recorded values for the motor amps attribute. We can do this using the
stream controllers GetRecorded method. A link to this endpoint is provided under the attribute.
To change the time range for the values we want returned we can look at
the documentation and see that this method takes a start time and end time parameter.
If we want to limit our return results to only five we can add a max count parameter
and if we only want values greater than 75 to be returned we can add a filter expression parameter.
Now let's change our request to get interpolated values at evenly spaced
timestamps rather than the raw recorded values. We can do this using the stream
controllers GetInterpolated method. If we look again at the documentation for
this endpoint we see that in addition to the start and end time parameters
we can also specify an interval parameter to determine the spacing of the return values.
To have the request only return timestamps and values we can add a selected fields parameter.
Our next task is to retrieve a calculated value for the average of this attribute
over the last week. We can use the stream controllers GetSummary method to do this.
Looking at the help page we can see that the URL parameter summary type specifies
which type of calculation we want returned, so we'll specify our summary type to be average.
For the last step we'll open the Chrome developer tools by pressing f12 and look at some of the
other information that's available there. This gives us a more detailed look at what is being
sent from the browser and returned by the PI Web API. If we go to the network tab and refresh our
page we can see that the request was sent and we can see the response from the server. The
response code was 200 which is good and we can also see the response headers in this view,
for example the server header, this can be very useful for troubleshooting.