Paginating Responses

Paginating a response can improve API performance by limiting the returned query results, spreading the results across multiple pages. Paginating responses also prevents overloading a user interface with too much returned data, and allows for paging forward and backward within a data set.

The following Shopper APIs support pagination:

You can control the number of results per page with the pageSize query parameter. The pageNumberparameter indicates the page to return in a paginated response. By default, the response returns the first page unless otherwise specified. The following table describes optional paging parameters:

Parameter
Description
pageNumber
The number indicating the page to return in a paginated response. Default: 1 (first page).
pageSize
The number of items to include on each page of a paginated response. Default: 25.

Paginated Requests Examples

Paginated Orders

The following example gets all orders.

Resource Method

GET shoppers/me/orders

URI

This example explicitly specifies the pageSize default value of 1.

GET shoppers/me/orders?pageSize=1

Request Headers

Host: api.digitalriver.com
User-Agent: API Client/1.0
Accept: application/xml
Authorization: bearer your_access_token

Request Body

The request body should be empty.

Response Header

HTTP/1.1 200 OK
Content-Type: application/xml; charset=UTF-8

Response Body

<orders uri="https://api.digitalriver.com/v1/shoppers/me/orders">
   <order uri="https://api.digitalriver.com/v1/shoppers/me/orders/12345678901"/>
   <order uri="https://api.digitalriver.com/v1/shoppers/me/orders/12345678902"/>
   <totalResults>2</totalResults>
   <totalResultPages>1</totalResultPages>
</orders>

Paginated Products

The following example gets all products, paginates the results, and specifies a result page.

Resource Method

GET shoppers/me/products

URI

This example requests to return the sixth page in the response by setting pageNumber to 6.

GET shoppers/me/products?pageNumber=6&pageSize=1

Request Headers

Host: api.digitalriver.com
User-Agent: API Client/1.0
Accept: application/xml
Authorization: bearer your_access_token

Request Body

The request body should be empty.

Response Header

HTTP/1.1 200 OK
Content-Type: application/xml; charset=UTF-8

Response Body

One product per page was returned since pageSizewas set to 1.

<products uri="https://api.digitalriver.com/v1/shoppers/me/products">
   <product uri="https://api.digitalriver.com/v1/shoppers/me/products/208124400">
      <displayName>Class VIII Weekly Auto Renewal Subscription</displayName>
      <thumbnailImage>http://drh-sys-ora.img.digitalriver.com/Storefront/Company/demosft1/images/product/thumbnail/ClassVIIImini.jpg</thumbnailImage>
      <pricing>
         <formattedListPrice>$79.99</formattedListPrice>
         <formattedSalePriceWithQuantity>$0.00</formattedSalePriceWithQuantity>
      </pricing>
      <addProductToCart cartUri="https://api.digitalriver.com/v1/shoppers/me/carts/active?productId=208124400" uri="https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items?productId=208124400"/>
   </product>
   <totalResults>20</totalResults>
   <totalResultPages>20</totalResultPages>
</products>

Paginated Results Metadata

Metadata fields located near the end of a response body indicate the total number of results and total number of pages:

...
 <totalresults>3</totalresults>
 <totalresultpages>1</totalresultpages>
...

Next and Previous Page Links

The nextPage and previousPage resource links are available for paginated responses. The resource fields are located near the top of a response body, as shown in line numbers 2 and 3 below:

1.  <products  uri="https://api.digitalriver.com/v1/shoppers/me/products">
2.     <nextPage  uri="https://api.digitalriver.com/v1/shoppers/me/products?pageNumber=7&pageSize=1"/>
3.     <previousPage uri="https://api.digitalriver.com/v1/shoppers/me/products?pageNumber=5&pageSize=1"/>
4.     <product uri="https://api.digitalriver.com/v1/shoppers/me/products/208124400">
5.        <displayName>Class VIII Weekly Auto Renewal Subscription</displayName>
6.        <thumbnailImage>.../images/product/thumbnail/ClassVIIImini.jpg</thumbnailImage>
7.        <pricing>
8.           <formattedListPrice>$79.99</formattedListPrice>
9.           <formattedSalePriceWithQuantity>$0.00</formattedSalePriceWithQuantity>
10.       </pricing>
11.       <addProductToCart cartUri="https://api.digitalriver.com/v1/shoppers/me/carts/active?productId=208124400" uri="https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items?productId=208124400"/>
   </product>