O2M Logo
One to Many
Pagination
Was this page helpful?

Pagination

Lists come a page at a time. Pass back next to get the following page.

Overview

Pagination splits a long list into pages. O2M uses a cursor: each page tells you how to get the next one.

How it works

A list answers with its rows and next. To get the following page, send next back as cursor. When next is null you have reached the end.

cURL
curl "https://api.o2m.in/api/v1/movements?limit=100" \
  -H "X-Access-Key: $O2M_ACCESS_KEY" \
  -H "X-Secret-Key: $O2M_SECRET_KEY"
Response
{
  "movements": [
    "…100 rows…"
  ],
  "next": "812"
}
cURL
curl "https://api.o2m.in/api/v1/movements?limit=100&cursor=812" \
  -H "X-Access-Key: $O2M_ACCESS_KEY" \
  -H "X-Secret-Key: $O2M_SECRET_KEY"

next is a marker, not a page number. Pass it back unchanged and do not build one yourself.

Page sizes and order

EndpointRows keyDefaultMostOrder
GET /stockitems100500By product
GET /movementsmovements100500Oldest first
GET /ordersorders50500Oldest order first
GET /shipmentsshipments100500Oldest parcel first

Read every page

Node.js
async function readAll(path, rowsKey) {
const rows = [];
let cursor = null;
do {
  const url = new URL("https://api.o2m.in/api/v1" + path);
  url.searchParams.set("limit", "500");
  if (cursor) url.searchParams.set("cursor", cursor);
  const response = await fetch(url, { headers: {
    "X-Access-Key": process.env.O2M_ACCESS_KEY,
    "X-Secret-Key": process.env.O2M_SECRET_KEY,
  } });
  if (!response.ok) throw new Error(`O2M answered ${response.status}`);
  const page = await response.json();
  rows.push(...page[rowsKey]);
  cursor = page.next;
} while (cursor);
return rows;
}

const orders = await readAll("/orders", "orders");

Keep up with changes

To collect only what is new:

ListHow to follow it
MovementsMovements never change. Keep the last next you received and pass it as cursor next time.
Stock, orders, shipmentsRecords can change after they are created, so pass updated_since with the time of your last read, for example 2026-10-02T10:00:00Z. Read all its pages each time.

Tip  Take the time just before you start reading, and use that as the next updated_since. Nothing that changes while you read is then missed.