FulfillbotDocs
Menu
MarkdownDownload

Pagination

List endpoints return one page at a time. Ask for a page with page, a whole number from 1 to 10,000 (default 1). Each page has up to 50 items; the page size can't be changed.

{ "success": true, "data": [{ "id": "cm3o7rd0e0001h2j3k4l5m6n" }], "meta": { "total": 120, "page": 2, "limit": 50, "pageCount": 3 } }
  • total is the number of items in the whole list, pageCount the number of pages, limit the page size and page the page you asked for.
  • A page after the last one returns an empty data list (for example "data": [], "meta": { "total": 120, "page": 4, "limit": 50, "pageCount": 3 }, with meta.page set to the page you asked for), so reading until data is empty works as well as reading up to pageCount.
  • A page that isn't a whole number from 1 to 10,000 returns 422 validation_failed.
  • Each endpoint says how its list is sorted: most are newest first, inventory is sorted by SKU.
  • Lists can change while you read them: a new item pushes the others one place on. To mirror your orders, use Incremental sync.

Reading every page

async function listAll(path) {
  const items = [];
  for (let page = 1; ; page += 1) {
    const response = await fetch(`https://api.rephut.com/v1${path}?page=${page}`, { headers: { Authorization: `Bearer ${process.env.FULFILLBOT_API_KEY}` } });
    if (!response.ok) throw new Error(`HTTP ${response.status}`);
    const { data, meta } = await response.json();
    items.push(...data);
    if (data.length === 0 || page >= meta.pageCount) return items;
  }
}

const products = await listAll("/products");
console.log(products.length, "products");
import os

import requests


def list_all(path):
    items = []
    page = 1
    while True:
        response = requests.get(
            f"https://api.rephut.com/v1{path}",
            params={"page": page},
            headers={"Authorization": f"Bearer {os.environ['FULFILLBOT_API_KEY']}"},
            timeout=30,
        )
        response.raise_for_status()
        body = response.json()
        items.extend(body["data"])
        if not body["data"] or page >= body["meta"]["pageCount"]:
            return items
        page += 1


products = list_all("/products")
print(len(products), "products")