OCAPI Pagination

The Open Commerce API uses paging whenever it accesses a collection of resource instances. Paging enables the API to return data in chunks, instead of returning a complete collection all at once. Each chunk, depending on its position, links to the previous chunk and to the next chunk. You can explicitly configure paging by providing values for the start and count parameters:

  • start: Specifies the start location of the chunk within the collection of resource elements. Valid values range from 0 to 999; the default value is 0. The start location isn’t a page number; it’s the position of the start element within the entire collection.
  • count: Specifies the number of resource instances to return in each chunk. Valid values range from 0 to 200; the default value is 25.

In the following example, a product search yields a collection of 99 total resource instances (shoes). The start property specifies that the requested chunk should start at position 10, and the count element specifies that the chunk should contain at most 5 resource instances. In the response, you can see the presence of the next and previous links; these links enable your application to navigate through the entire collection one chunk at a time.

1REQUEST:
2GET /dw/shop/v24_5/product_search?q=shoes&start=10&count=5 HTTP/1.1
3Host: example.com
4Accept: application/json
5
6RESPONSE:
7HTTP/1.1 200 OK
8Content-Length: 351
9Content-Type: application/json; charset=UTF-8
10
11{
12  "_v" : "24.5",
13  "query":"shoes",
14  "total":99,
15  "start":10,
16  "count":5,
17  "next":"http://example.com/dw/shop/v24_5/product_search?q=shoes&start=15&count=5",
18  "previous":"http://example.com/dw/shop/v24_5/product_search?q=shoes&start=5&count=5",
19  "hits":[{
20    "product_id":123",
21    "link":"http://example.com/dw/shop/v24_5/product/123",
22    "name":"My Ultimate Shoe",
23    ...
24    },
25    ...
26  ]}

Attention!

The Open Commerce API (OCAPI) is now deprecated. The provisions described in our versioning and deprecation policy fully apply. For all new projects and major refactoring work, use B2C Commerce API (SCAPI) as the default REST API. For additional details, refer to Why Use SCAPI Instead of OCAPI.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!