Skip to content

Pagination

List endpoints return 25 items per page. The page size is fixed. Use page to move through results.

ParameterTypeDescription
pageintegerPage to return. Defaults to 1.
bash
curl "https://api.canteenweb.com/api/v1/admin/orders?page=2" \
  -H "Authorization: Bearer your-access-token" \
  -H "X-CANTEEN-ORGANIZATION: your-org-uuid"

Response

Paginated responses add links and meta next to data. The URLs in links keep the filters you sent, so following links.next is enough to walk a filtered list.

json
{
  "data": [],
  "links": {
    "first": "https://api.canteenweb.com/api/v1/admin/orders?page=1",
    "last": "https://api.canteenweb.com/api/v1/admin/orders?page=5",
    "prev": "https://api.canteenweb.com/api/v1/admin/orders?page=1",
    "next": "https://api.canteenweb.com/api/v1/admin/orders?page=3"
  },
  "meta": {
    "current_page": 2,
    "from": 26,
    "last_page": 5,
    "path": "https://api.canteenweb.com/api/v1/admin/orders",
    "per_page": 25,
    "to": 50,
    "total": 120
  },
  "success": true,
  "message": "Request was successful."
}
FieldDescription
meta.current_pagePage you are on.
meta.last_pageNumber of pages.
meta.per_pageItems per page, always 25.
meta.totalTotal items matching the filters.
meta.from, meta.toPosition of the first and last item of this page in the full list.
links.prev, links.nextnull on the first and last page respectively.

meta also contains a links array meant for rendering page buttons. You can ignore it.

Walking every page

js
async function fetchAllOrders(params) {
  const headers = {
    'Authorization': 'Bearer your-access-token',
    'X-CANTEEN-ORGANIZATION': 'your-org-uuid',
    'Accept': 'application/json',
  }

  let url = 'https://api.canteenweb.com/api/v1/admin/orders?' + new URLSearchParams(params)
  const orders = []

  while (url) {
    const body = await (await fetch(url, { headers })).json()
    orders.push(...body.data)
    url = body.links.next
  }

  return orders
}

Fetch pages one after another. The rate limit is per minute, and a list of a few hundred orders is a handful of requests.

Private API. Access is granted per organization.