Skip to main content
The Trunk API uses conventional HTTP status codes to show whether a request succeeded or failed. In general:
  • Codes in the 2xx range mean that the request succeeded.
  • Codes in the 4xx range mean that the request failed because of the information it sent. For example, a required parameter is missing, the credential doesn’t have a permission, or the pull request is already in the queue. Most of these responses have an error code that tells you what went wrong.
  • Codes in the 5xx range mean that an error occurred on Trunk’s servers. These are rare.

HTTP status codes

Error envelope

Every error that the API returns has this shape:
Trunk can add new codes at any time. If you get a code that you don’t know, handle it as a general failure for its status code.

Responses without the envelope

Some responses come from Trunk’s edge or from the HTTP server, before the request gets to the API. These don’t have the envelope:
  • 401, and 403 for some credential problems. See Authentication errors.
  • 429 from the rate limiter.
  • 413 and 504, as plain text.
  • Gateway errors, such as 503.
Read error.code only when the body is JSON with an error object. Otherwise, branch on the status code.

Error codes

Each endpoint page shows the codes that the endpoint can return.

Retrying

  • Reads are safe to retry after 429, 500, 502, 503, 504, and network errors. Wait longer before each attempt (exponential backoff).
  • Writes don’t honor Idempotency-Key yet. If a write times out or returns 500, 502, 503, or 504, you don’t know if it was done. So read the resource back before you retry it. Writes that set a value, such as PATCH /v2/merge-queues/{id}/config and PUT /v2/impacted-targets, are safe to repeat.
  • Don’t retry 4xx responses unchanged, except 429. A 422 gets the same response until something about the resource changes.
When you contact support about a failed request, include its X-Request-Id header.