Cursor pagination
By default API calls will return 50 results. By using the limit parameter that can be increased to 250 results. When there are more results than the current limit a cursor may be used to request additional results.
Cursor based pagination is the preferred method for looping through all records in a given data set, as it is more performant than specifying a page number along with number of results. This method also provides more assurance that you will receive all of the records in a given set.
Cursor based pagination works by providing a reference to a specific item in a list of sequential data which will represent the cursor, such as a numeric id. You can then specify whether you would like to query records starting before or starting after that item.
For convenience, the API provides a Link header in all responses for which there are further pages. This header contains both a next_cursor and previous_cursor link, which is just a URL with an encoded page_info parameter that contains any filters from your first call, as well as markers to let the API know where it left off and where to begin for the next call.
Please note that the only compatible filter allowed to be used with cursors is limit.
Supported endpoints for Link |
|---|
GET /addresses |
GET /async_batches |
GET /async_batches/:id/tasks |
GET /charges |
GET /customers |
GET /discounts |
GET /orders |
GET /subscriptions |
/charges requests which supply either the updated_at_min or created_at_min filter will not currently return a Link header.Requests which contain a filter for ids,
shopify_product_ids will not return a Link header.URL="https://api.rechargeapps.com/charges?limit=5"
response=$(curl -s -w "%{http_code}"
-H 'X-Recharge-Access-Token: your_api_token'
-H 'X-Recharge-Version: 2021-11'
-X GET $URL)
content=$(sed '$ d' <<< "$response") # get all but the last line which contains the status code
# Display results
echo $content | jq "."
# parse next url
echo "Next URL"
next_cursor=$(jq ".next_cursor" <<< "${content}")
# Notice next_cursor value is passed as page_info query param
echo "$URL&page_info=$next_cursor"