Error Handling & HTTP Status Codes

HTTP · Status Codes · Error Handling

Error Handling

The API uses standard HTTP status codes and structured JSON error messages for consistent error handling.


HTTP Status Codes

CodeStatusDescription
200OKRequest successful (GET, POST, DELETE)
201CreatedNew resource created (POST)
400Bad RequestInvalid request body, missing parameters, or an unusable query parameter (on every JSON endpoint since v2.122.10, see below)
401UnauthorizedNo token or invalid token
403ForbiddenToken does not have the required scopes
404Not FoundResource not found
409ConflictResource cannot be deleted (safety check)
429Too Many RequestsRate limit exceeded; Retry-After states the wait time in seconds
500Internal Server ErrorServer error

Error Response Format

HTTP/1.1 401 Unauthorized
X-XoPort-Deny-Reason: deny_token_required
Content-Type: application/json; charset=utf-8

{
  "success": false,
  "api_version": "2.122.13",
  "error": {
    "code": "UNAUTHORIZED",
    "reason": "deny_token_required",
    "message": "Authentication required. JSON/REST routes always require an OAuth2 token and check its scopes; the XML_PORT_IP_FILTER whitelist does not authorize them (changed in API 2.119.0). Obtain a token via POST /oauth/token (client_credentials grant)."
  }
}

Errors involving query parameters also include details[] with param and message for each error (example on the Export API page). Evaluate error.code, not the message text.

Starting with v2.119.0, when a request is rejected, the API specifies the reason in the reason field; for a 401 error, it also includes the reason in the X-XoPort-Deny-Reason header: for example, deny_token_required (401, request without a token) or deny_ip_not_listed (403, address not in XOPORT_REST_IP_LIST; only in the body).

Common Error Codes

CodeHTTPDescription
INVALID_FILTER_VALUE400A query parameter carries an unusable value or a list value (?status[]=1); details[] names param and message for each error. Since v2.122.10 on every JSON endpoint, including Import and Delete; nothing is then read, written or deleted
INVALID_PAGINATION400limit, offset, page, sort, or order are unusable (details[] as above)
INVALID_RANGE400Unusable path form or path segment: new:{datum} on an endpoint other than customers and orders (since v2.122.10), and since v2.122.12 in the JSON export also a segment that is neither an integer nor a range nor a subroute (/product/42x, /order/42.0, /contracts/10/20). The message names the segment
FILTER_NOT_APPLICABLE400Filter on a single-record request or ID range where it has no effect; since v2.122.13 also ?categories_id= together with an ID or range in the path of the category product list (/categories/5/productlist?categories_id=7, /categories/5:10/productlist?categories_id=5). Only the same value as the single path ID remains allowed
INVALID_STATUS400status_id on the status endpoint PUT /Import/JSON/contracts/{id}/status is not a contract status of the shop or not an integer. Since v2.122.13, error.valid_status_ids lists the valid IDs; up to v2.122.12, the endpoint checked against the order statuses
UNKNOWN_FILTER200 or 400Unknown parameter name on the export: warning in warnings[], HTTP 400 with ?_strict=true
MISSING_ID400Delete without an ID in the path; the ID must be included in the path, for example DELETE /…/categories/99
UNAUTHORIZED401Missing, invalid or expired access token, or the client is disabled; error.reason and the header X-XoPort-Deny-Reason specify the reason
IP_NOT_ALLOWED403Request from an address not listed in XOPORT_REST_IP_LIST (since v2.119.0)
INSUFFICIENT_PERMISSIONS403The token lacks the endpoint’s scope (message: “Required scope: …”)
NOT_FOUND404Resource not found: single-record request without a match at /product/{id} and /products/{id} as well as /order_status/{id} (since v2.122.10), plus media, ticket attachments, documents and DELETE on an unknown ID. The other single-record requests respond with HTTP 200 and an empty data. An incorrect base URL also results in 404 NOT_FOUND
HAS_SUBCATEGORIES409Category has subcategories
HAS_PRODUCTS409Category contains products
HAS_NEWS409News category contains articles
HAS_ORDERS409Customer has orders
RATE_LIMIT_EXCEEDED429Client’s rate limit exceeded; since v2.122.11 with error.retry_after

The token endpoint POST /oauth/token responds in the OAuth2 format (error, error_description), not with these codes: see “Errors at the token endpoint” below.

A scope change on the client takes effect only with the next token: A token that has already been issued retains the scopes it had at the time of issuance until it expires, i.e., for up to one hour. You can withdraw access immediately in the backend with “Revoke Tokens” in the client’s action menu (as of shop 4.9.168); in older shops, deactivate and reactivate the client; the secret remains the same. A changed rate limit, by contrast, takes effect immediately.

The client’s usage log does not include export aborts with HTTP 400 before a query runs (filter, pagination and path errors), nor the 429 response. If you look for an error there, you will therefore not find these cases; the 400 responses still count toward the rate limit.

Changed in v2.122.10:
  • Unusable values and list values of query parameters result in HTTP 400 INVALID_FILTER_VALUE on every JSON endpoint (on Import and Delete “… Nothing was written” or “… Nothing was deleted”). Up to v2.122.9, such a filter was usually dropped silently, and the response came unfiltered with HTTP 200. Rules and examples: Export API.
  • GET /product/{id} and /products/{id} for a deleted or never assigned product result in HTTP 404 NOT_FOUND (message “Product with id=… not found”) instead of HTTP 200 with an empty data. If you abort on responses outside 2xx, you now get this case as an error.
  • new:{datum} on an endpoint other than customers and orders results in HTTP 400 INVALID_RANGE.
Changed in v2.122.12:
  • An unusable path segment in the JSON export results in HTTP 400 INVALID_RANGE. Up to v2.122.11, the paginated list came back under HTTP 200, and forms such as 1e3, 4.2, or +5 counted as an ID. Rules and examples: Export API, section “Path segment”.
  • Leading or trailing whitespace in a query value or an ID in the path no longer counts. Some requests that previously got past the value validation and silently behaved differently therefore now return an error or a different result, e.g. ?_strict=true%0A with an unknown filter now returns HTTP 400.
Changed in v2.122.13:
  • Contract status: The status endpoint PUT /Import/JSON/contracts/{id}/status checks status_id against the shop’s contract statuses instead of the order statuses. An ID that exists only as an order status now results in HTTP 400 INVALID_STATUS; a contract status that does not also exist as an order status is written. Read the IDs from contracts_statuses[] of GET /Export/JSON/contracts or from error.valid_status_ids, never from /order_statuses. The contract import reports an invalid ID (for example an ID that exists only as an order status) with the warning CONTRACT_STATUS_UNKNOWN: the record is written, the status is not.
  • Category product list: ?categories_id= together with an ID or range in the path results in HTTP 400 FILTER_NOT_APPLICABLE, except with the same value as the single path ID. Up to v2.122.12, the category of the parameter came back under HTTP 200. Send the category either in the path or as a parameter.

Rate limit exceeded (429)

Since v2.122.11 Retry-After states the seconds until a request is accepted again (1 to 3600), and the body carries the same number as error.retry_after. In addition, there are the headers X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset, which every response to a client with a rate limit carries (see OAuth2 Clients).

HTTP/1.1 429 Too Many Requests
Retry-After: 1260
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1792327500
Content-Type: application/json; charset=utf-8

{
  "success": false,
  "api_version": "2.122.13",
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Rate limit of 5000 requests per 3600 s (sliding window) exceeded.",
    "retry_after": 1260
  }
}
  • Retry-After is what counts for the next attempt. In most cases, “now + Retry-After” is exactly X-RateLimit-Reset; if a client’s limit has just been lowered, Retry-After points to a later time.
  • Up to v2.122.10 (shop up to 4.9.170), Retry-After was always 3600; there was no retry_after field, and the message read “Rate limit of 5000 requests/hour exceeded.” Evaluate error.code, never the message text.
  • A rejected request (429) does not count. Distribute many requests evenly over the hour and slow down as soon as X-RateLimit-Remaining reaches 0, rather than waiting for the 429.

Errors at the token endpoint

POST /oauth/token responds in the OAuth2 format with error and error_description. Since v2.122.11 a requested scope that cannot be read (invalid UTF-8 or a list such as scope[]=…) results in HTTP 400 invalid_scope; no token is issued. client_id or client_secret as a list results in HTTP 400 invalid_request. At the token endpoint’s own limit, Retry-After states the wait time (1 to 300 seconds). All errors of the token endpoint are listed under OAuth2 Clients.

Best Practice

Always check the success field in the response and implement retry logic for 429 and 5xx errors.