Errors & status codes

How the API signals success and failure
View as Markdown

Every response from the Lemmy API uses the same envelope, whether the request succeeds or fails. Each response contains:

FieldTypeDescription
IsSuccessbooleanWhether the request succeeded.
ErrorMessagesarray of stringsHuman-readable messages describing what went wrong. Empty when IsSuccess is true.
payloadvariesThe requested data or created records. The field name depends on the endpoint — for example CustomerGroups, Customers, or Orders.

Checking for success

IsSuccess and the HTTP status code always agree, so you can rely on either:

  • IsSuccess: true → HTTP 200 OK, and ErrorMessages is empty.
  • IsSuccess: false → HTTP 400 Bad Request, and ErrorMessages explains why.

Always check IsSuccess (or the status code) before using the payload.

A successful response:

1{
2 "IsSuccess": true,
3 "ErrorMessages": [],
4 "CustomerGroups": [
5 { "Code": "RETAIL", "Description": "Retail customers", "Active": true }
6 ]
7}

A failed response:

1{
2 "IsSuccess": false,
3 "ErrorMessages": [
4 "x-page-offset header is required"
5 ]
6}

Status codes

StatusMeaningWhen it happens
200 OKSuccessThe request succeeded (IsSuccess: true).
400 Bad RequestRequest rejectedA validation or business error occurred (IsSuccess: false). See common causes below.
401 UnauthorizedAuthentication failedMissing or invalid API key. See Authentication.
500 Internal Server ErrorServer errorThe request body was malformed JSON, or an unexpected error occurred on the server.

Common causes of a 400

  • Missing x-page-offset or x-page-limit headers on a GET request — see Pagination.
  • Missing or invalid required fields in a POST request body.
  • Any other validation error — read ErrorMessages for the specifics.

Handling errors

Check IsSuccess before trusting the payload, and surface ErrorMessages when something goes wrong:

1response = requests.get(url, headers=headers) # headers include x-api-key and x-company-id
2body = response.json()
3
4if not body["IsSuccess"]:
5 raise RuntimeError("; ".join(body["ErrorMessages"]))
6
7# Safe to use the payload
8process(body)