The number of items retrieved in the payload in response to a request is set by default to 25 but, from Smart Electrical Web API 2.1.3, can be set to any other value (up to 1000) using the odata.maxpagesize parameter (for details, see GET Requests to expose Items and their Properties). The pagination uses $top and $skip query options to select the next set of data. We recommend including the $orderby method on properties with distinct values as part of the request, so that pagination is consistent. In addition, we recommend including $count=true so that the next link is provided by the API only where there are additional items to go to.
The system queries add options to the request that help with keeping count of the number of items displayed in the result.
Method |
Description |
---|---|
$orderby |
The $orderby System query option specifies the order in which items are returned from the service. |
$top |
The $top System query option specifies a non-negative integer n that limits the number of items returned from a collection. |
$skip |
The $skip system query option specifies a non-negative integer n that excludes the first n items of the queried collection from the result |
Pagination default
This request fetches the Items in ascending order, using the $orderby method to sort the items by Item Tag.
-
Duplicate the request 03.04 Motors + order by Item Tag Asc + selected properties.
-
Add the $count=true method to the request.
https://apiservername.domain.com/WebApi/SEL/V2/Sites('WEBAPISITE001')/Plants('PLANT001')/Motors/Com.Ingr.SEL.V2.WEBAPISITE001.PLANT001.Motor/?$count=true&$orderby= ItemTag&$select=Id,ItemTag,MotorRatedPower,RatedVoltage,aabbcc_code
The bottom of the response displays a link to the next items, skipping the first 25 items:
-
Copy the link and paste it in the GET address bar to retrieve the next set of 25 items.
Pagination top items
This request uses '$top' to include only the top number of items in the result. In this case, the request will display only the top three items in the payload (motors ordered by Item Tag).
-
Select the request 05.01 Pagination top items and click Send.
-
At the end of the previous request, add &$top=3 and click Send.
https://apiservername.domain.com/WebApi/SEL/V2/Sites('WEBAPISITE001')/Plants('PLANT001')/Motors/Com.Ingr.SEL.V2.WEBAPISITE001.PLANT001.Motor/?$count=true&$orderby= ItemTag&$select=Id,ItemTag,MotorRatedPower,RatedVoltage,aabbcc_code&$top=3
Pagination skip items
This request uses '$skip' to exclude the first n items in the result. In this case, the request will skip the first two items and display the next three items in the payload.
-
Select the request 05.02 Pagination top / skip items and click Send.
https://apiservername.domain.com/WebApi/SEL/V2/Sites('WEBAPISITE001')/Plants('PLANT001')/Motors/Com.Ingr.SEL.V2.WEBAPISITE001.PLANT001.Motor/?$count=true&$orderby= ItemTag&$select=Id,ItemTag,MotorRatedPower,RatedVoltage,aabbcc_code&$top=3&$skip=2
-
Select the request 05.01 Top items again and click Send.
-
Compare the results of both requests and notice that the first record of the current request is the same as the third record of the previous request.
Pagination top items related to a specific item
This request expands the top two plant items on side 1 of a motor with Id=0584D3F3D20F4EF0BDCC11C943994F7C2. You will need to choose a motor Id appropriate for your data set.
-
Select the request 05.03 Top 2 plant items for specific motor and click Send.
https://apiservername.domain.com/WebApi/SEL/V2/Sites('WEBAPISITE001')/Plants('PLANT001')/Motors('0584D3F3D20F4EF0BDCC11C943994F7C2')/PlantItems/Com.Ingr.SEL.V2.WEBAPISITE001.PLANT001.PlantItem/?$count=true&$orderby= ItemTag&$select=Id,ItemTag,aabbcc_code&$top=2