Top and Skip
The query options $top and $skip allow you to specify the number of entries to return, or to specify a subset of a collection to return.
$top
Use the $top query option to specify the total number of entries to return for each page of results. The value for $top must be an integer greater than or equal to 0 (zero). If the specified value is less than 0, the URI is considered malformed and the request results in an error.
The query parameter $orderby is not supported, so the data service must return a fully ordered Collection.
For example, the following request returns the first two Product entries for the specified service.
https://localhost:9002/odata2webservices/InboundProduct/Products?$top=2
The system returns a response with a link to the next page that you can use to view additional retrieved items.
{
"d": {
"results": [
{
"__metadata": {
"id": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article1')",
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article1')",
"type": "HybrisCommerceOData.Product"
},
"code": "test_article1",
"name": "test_article1",
"integrationKey": "Staged|Default|test_article1",
"catalogVersion": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article1')/catalogVersion"
}
},
"unit": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article1')/unit"
}
}
},
{
"__metadata": {
"id": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article2')",
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article2')",
"type": "HybrisCommerceOData.Product"
},
"code": "test_article2",
"name": "test_article2",
"integrationKey": "Staged|Default|test_article2",
"catalogVersion": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article2')/catalogVersion"
}
},
"unit": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article2')/unit"
}
}
}
],
"__next": "https://localhost:9002/odata2webservices/InboundProduct/Products?$top=2&$skiptoken=2"
}
}
$skip
Use the $skip query option to retrieve a subset of the collection, starting at the element after the value specified. The value of $skip must be an integer greater than or equal to 0 (zero). If the value specified is less than 0, the URI is considered malformed and the request results in an error.
The query parameter $orderby is not supported, so the data service must return a fully ordered Collection.
For example, the following request returns products starting with the third product listed. The data service defines the order of the product list. The default page size determines the number of items returned. See the Query Option Defaults section of this topic.
https://localhost:9002/odata2webservices/InboundProduct/Products?$skip=2
The request returns the following response:
{
"d": {
"results": [
{
"__metadata": {
"id": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article3')",
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article3')",
"type": "HybrisCommerceOData.Product"
},
"code": "test_article3",
"name": "test_article3",
"integrationKey": "Staged|Default|test_article3",
"catalogVersion": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article3')/catalogVersion"
}
},
"unit": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article3')/unit"
}
}
},
{
"__metadata": {
"id": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article4')",
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article4')",
"type": "HybrisCommerceOData.Product"
},
"code": "test_article4",
"name": "test_article4",
"integrationKey": "Staged|Default|test_article4",
"catalogVersion": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article4')/catalogVersion"
}
},
"unit": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article4')/unit"
}
}
}
],
"__next": "https://localhost:9002/odata2webservices/InboundProduct/Products?$skiptoken=4"
}
}
Pagination using $top and $skip
Using the $top and $skip options together, you can specify the number of entries to return for each page in a list of paginated results that starts at the element after the value set for $skip. For example, to view page 3 of the results with 10 results per page, use the parameters $top=10, $skip=20. The system returns items 21 through 30. If you do not provide either or both of the $top and $skip values, the system uses the default values, described in the Query Option Defaults section of this topic.
The following request uses $skip and $top to paginate a collection of Product Entries that the service returns, starting after the fourth item.
https://localhost:9002/odata2webservices/InboundProduct/Products?$top=2&$skip=4
The response returns two Products, starting with the fifth item, from the ordered collection of Entries that the service returns, as shown.
{
"d": {
"results": [
{
"__metadata": {
"id": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article5')",
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article5')",
"type": "HybrisCommerceOData.Product"
},
"code": "test_article5",
"name": "test_article5",
"integrationKey": "Staged|Default|test_article5",
"catalogVersion": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article5')/catalogVersion"
}
},
"unit": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article5')/unit"
}
}
},
{
"__metadata": {
"id": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article6')",
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article6')",
"type": "HybrisCommerceOData.Product"
},
"code": "test_article6",
"name": "test_article6",
"integrationKey": "Staged|Default|test_article6",
"catalogVersion": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article6')/catalogVersion"
}
},
"unit": {
"__deferred": {
"uri": "https://localhost:9002/odata2webservices/InboundProduct/Products('Staged%7CDefault%7Ctest_article6')/unit"
}
}
}
]
}
}