Skip to main content

Pagination and errors

Pagination​

Paginated endpoints take page and page_size as query parameters, defaulting to page 1 and 50 per page:

curl "$ALRIK_API_BASE/v1/order_drafts?origin_reference=wh-stockholm-01&page=2&page_size=100" \
-H "x-api-key: $ALRIK_API_KEY"

They return a fixed envelope:

{
"page": 2,
"size": 100,
"has_next_page": true,
"items": [ ... ]
}
size echoes page_size

size is the page size you requested, not the number of items returned — on the last page items is shorter than size. Use has_next_page to detect the end of the list.

There is no total count. Page until has_next_page is false:

page = 1
while True:
res = get("/v1/order_drafts", params={
"origin_reference": "wh-stockholm-01",
"page": page,
"page_size": 100,
})
handle(res["items"])
if not res["has_next_page"]:
break
page += 1

Some endpoints cap page_size:

EndpointMaximum page_sizeIf you exceed it
GET /v1/company/orders1000400 {"detail": "Page size too large"}
GET /v1/tours/active1000400 {"detail": "Page size too large"}
GET /v1/vehicles500422 validation error

Date range limits​

The maximum span differs per endpoint — it is not 31 days everywhere:

EndpointMaximum spanIf you exceed it
GET /v1/orders31 days400 {"detail": "Date range too long, max 31 days"}
GET /v1/tours/billable91 days400 {"detail": "Date range too long"}
GET /v1/stats/engagement91 days400 {"detail": "Date range too long"}
GET /v1/company/ordersNo limitA two-year range returns 200. Page through it instead
GET /v1/order_draftsNo limitTakes optional created_at and converted_at windows rather than a required range
GET /v1/tours/active—Takes a single optional scheduled_date, defaulting to today
A safe default

If you can, page in 31-day windows everywhere — that works against every endpoint.

Error shapes​

There are two different error bodies, and which one you get depends on the kind of failure.

Most errors: detail​

Permission failures, unknown locations, bad ranges and business-rule violations all return a single string:

{ "detail": "Permission 'allow_order_creation' is required but not granted for this integration" }

Validation errors: a custom envelope​

When the request body or query parameters fail schema validation, the response is shaped differently:

{
"status_code": 10422,
"message": "[{'type': 'missing', 'loc': ('query', 'end_date'), 'msg': 'Field required', 'input': None}]",
"data": null
}
Reading the validation envelope

The HTTP status is 422. status_code in the body is Alrik's own error code (10422 for validation failures), not the HTTP status. message is a human-readable description of what failed — log it rather than parsing it.

Branch on the HTTP status: handle this envelope on 422 and the detail shape on everything else.

Status codes​

StatusMeaning
200Success
201Created — SCIM user creation
202Accepted — SCIM group creation, processed asynchronously
204No content — SCIM user deletion
400A business rule was broken: missing leg, range too wide, page too large
401The API key is not recognised
403Missing key, missing permission, unowned location, or no company
404Vehicle not found, deleted, or at another location
409Vehicle external_id already in use at the location
422Schema validation failed — uses the 10422 envelope
500Internal failure

Retrying​

  • 4xx — do not retry. The request needs changing; the body says what to fix.
  • 500 — retry with exponential backoff.
Check before retrying a create

POST /v2/order/draft creates a new order on every call, including a repeated origin_order_number. If a create times out, look for the order in GET /v1/order_drafts by its origin_order_number before sending it again. See Send orders from your ERP.