Pagination
List endpoints, such as GET /deliveries and GET /wallet/transactions, use cursor pagination. Lists are newest first.
Parameters
| Parameter | Description |
|---|---|
limit | How many items to return. For example limit=50. The maximum is 100. |
starting_after | An object id. Returns the items after it. Pass the last id of the previous page. |
The response carries has_more: true when there is another page.
There is no total count. This keeps lists fast as they grow.
Example
curl "https://api.getreeds.co/shipping/v1/deliveries?limit=2&starting_after=dlv_9Kd3Qx7M" \
-H "Authorization: Bearer $REEDS_ACCESS_TOKEN"
Response 200
{
"status": "success",
"data": [
{ "id": "dlv_8Pq4Ns2L", "...": "a delivery object" },
{ "id": "dlv_7Hn2Lk1C", "...": "a delivery object" }
],
"has_more": true
}
For the next page, call again with starting_after=dlv_7Hn2Lk1C. Stop when has_more is false.
Fetch all pages
- cURL
- Node.js
- PHP
- Python
# Requires jq
CURSOR=""
while true; do
URL="https://api.getreeds.co/shipping/v1/deliveries?limit=100"
[ -n "$CURSOR" ] && URL="$URL&starting_after=$CURSOR"
PAGE=$(curl -s "$URL" -H "Authorization: Bearer $REEDS_ACCESS_TOKEN")
echo "$PAGE" | jq -c '.data[]'
[ "$(echo "$PAGE" | jq -r '.has_more')" = "true" ] || break
CURSOR=$(echo "$PAGE" | jq -r '.data[-1].id')
done
async function* allDeliveries() {
let startingAfter;
while (true) {
const url = new URL('https://api.getreeds.co/shipping/v1/deliveries');
url.searchParams.set('limit', '100');
if (startingAfter) url.searchParams.set('starting_after', startingAfter);
const res = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.REEDS_ACCESS_TOKEN}` },
});
const body = await res.json();
yield* body.data;
if (!body.has_more) return;
startingAfter = body.data[body.data.length - 1].id;
}
}
for await (const delivery of allDeliveries()) {
console.log(delivery.id, delivery.status);
}
<?php
function all_deliveries(): Generator {
$startingAfter = null;
do {
$query = ['limit' => 100];
if ($startingAfter) $query['starting_after'] = $startingAfter;
$ch = curl_init('https://api.getreeds.co/shipping/v1/deliveries?' . http_build_query($query));
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('REEDS_ACCESS_TOKEN')],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
foreach ($body['data'] as $delivery) yield $delivery;
$startingAfter = $body['data'] ? end($body['data'])['id'] : null;
} while ($body['has_more']);
}
foreach (all_deliveries() as $delivery) {
echo $delivery['id'], ' ', $delivery['status'], PHP_EOL;
}
import os
import requests
def all_deliveries():
starting_after = None
while True:
params = {"limit": 100}
if starting_after:
params["starting_after"] = starting_after
res = requests.get(
"https://api.getreeds.co/shipping/v1/deliveries",
headers={"Authorization": f"Bearer {os.environ['REEDS_ACCESS_TOKEN']}"},
params=params,
timeout=30,
)
body = res.json()
yield from body["data"]
if not body["has_more"]:
return
starting_after = body["data"][-1]["id"]
for delivery in all_deliveries():
print(delivery["id"], delivery["status"])
tip
Newest first means new items appear at the start of the list while you page. Pages you have already read don't shift, so you won't see duplicates or skip items.