Error Handling

The error model (code, detail, source, correlation ID), the HTTP codes the API returns, and partial success (207) on bulk updates.

The Spendesk API follows standard conventions using HTTP response codes.

Error Model

Errors share a consistent model, which provides additional detail, where necessary, to help resolve the error(s):

{
  "correlationId": "a3b8e2f1-4c5d-4e6f-9a0b-1c2d3e4f5a6b",
  "errors": [
    {
      "code": "BAD_REQUEST_INCORRECT_OR_MISSING_FIELD",
      "detail": "There is a validation error with incorrect field in request body. Please fix and repeat your request.",
      "source": "type"
    },
    {
      "code": "BAD_REQUEST_INCORRECT_OR_MISSING_FIELD",
      "detail": "There is a validation error with incorrect field in request body. Please fix and repeat your request.",
      "source": "bookkeepingStatus"
    }
  ]
}
  • errors - one or more errors, each with a stable code, a human-readable detail and, for validation errors, the source field at fault;
  • correlationId - the identifier of your request, also returned in the x-correlation-id response header. Include it when you contact support about a failed call.

HTTP Codes

These are the common standard HTTP response codes that will be used when there is an error in your request:

HTTP CodecodeDescription
400BAD_REQUEST_INCORRECT_OR_MISSING_FIELDBad Request - something in the request was not as expected. The response body says which field and, for a value outside a list, the allowed values.
400RESPONSE_TOO_LARGEThe answer would exceed 512,000 bytes. Narrow the request: a shorter date range, more filters or a smaller page. Retrying the same request does not help.
401AUTHENTICATION_ERRORAuthentication Error - check your access token. When it has expired, the message says so ("The access token has expired. Request a new token."): request a new one. The response carries a WWW-Authenticate: Bearer header.
403FORBIDDEN_ERRORForbidden - you're trying to access something you don't have the correct privileges for. Try reviewing the scope of your API credentials or access token.
404NOT_FOUNDNot Found - the resource you're requesting doesn't exist. List endpoints also return 404 for a page past the last one — see Pagination.
409CONFLICT_ERRORConflict - the request conflicts with the current state of the resource, or a limit was reached (for example the number of open payable snapshot requests).
413LARGE_BODY_ERRORPayload Too Large - the request body or the uploaded file is too large.
415UNSUPPORTED_MEDIA_TYPEUnsupported Media Type - the type of the uploaded file is not accepted.
415UNSUPPORTED_MEDIA_TYPE_ERRORThe body was sent with a Content-Type the API cannot read (for example application/xml, or a malformed header). Send JSON with Content-Type: application/json.
422-Unprocessable - the request is valid but cannot be applied in the resource's current state. The body gives a reason instead of the errors list.
422EXPORT_FAILEDA journal export ran but failed. detail gives the reason, for example a payable that cannot be turned into a journal line.
429TOO_MANY_REQUESTSToo Many Requests - you have made too many requests and hit the rate limit. Wait the number of seconds in the Retry-After header, then retry — see Rate Limiting.
500INTERNAL_SERVER_ERRORInternal Server Error - something has gone wrong on our side, best to contact our support with the correlationId.
503SERVICE_UNAVAILABLE_ERRORService Unavailable - the feature is temporarily unavailable (for example payable snapshots). Retry later.

Partial success on bulk updates

Bulk updates — Update bookkeeping status of payables and Update state of settlements — return 207 Multi-Status when some items were updated and others were not. Check the outcome of each item: updated, or notUpdated with a reason such as notFound or invalidState.

{
  "updatedPayables": [
    { "id": "bc9cef35-401d-4ea4-b384-ed725e6685cf", "outcome": "updated" },
    { "id": "5d1f0a2e-7b6c-4e3d-9f8a-2b1c0d9e8f7a", "outcome": "notUpdated", "reason": "invalidState" }
  ]
}