Every failed TripWorks API request returns a stable error code you can branch on. Reading the code, not the message, keeps your integration working when wording changes, because the message is written for people and can be reworded at any time. This article explains what an error response contains, which codes you will meet most often, and what to do about each.
In this article
In this article
- What an error response contains
- Which error codes to expect, and what to do about each
- How to find a failed request again later
What does an error response look like?
A response always includes a success boolean. When a request fails, it also includes a human-readable message and a structured error object with a stable code. The message is written for people and its wording can change. The code is written for your software and stays the same, so branch on the code.
{
"success": false,
"message": "The key doesn't have the scope this request needs.",
"error": { "code": "insufficient_scope" }
}
Which error codes will you meet?
These are the codes you will see most often, and what to do about each:
-
insufficient_scope(status403). The key is valid but doesn't have permission for this object. Edit the key's permissions. See How API keys and access work. -
too_many_requests(status429). The key or the account went over an allowance. Pause, retry with a growing delay, and fetch less. See Build integrations that stay fast and efficient. -
validation_failed(status422). A value in your request isn't valid. The response lists each field that failed, so you can show or fix each one. -
unknown_fields. The request includes a field TripWorks doesn't accept for that operation. Remove it, or check its spelling in the API reference. -
not_found. The record you asked for doesn't exist. -
decision_required(status409). Not a failure. TripWorks needs a choice from you before it can finish, and nothing was changed. See How decisions work in the REST API.
Two more cases return a status without a record-level code: a request with no key or a malformed key gets a 401, and a filter or sort the object doesn't support gets a 422.
When you are tracking down a failure, note the request ID. Every request has one, and it's how you and TripWorks support find exactly what was sent and returned.
Examples
-
Branch on the code. When a request fails, read
error.code. Pause ontoo_many_requests, fix permissions oninsufficient_scope, and show the field errors onvalidation_failed. -
Show the user what to fix. On
validation_failed, list each failed field next to the matching input in your own screen. -
Retry with patience. On
too_many_requests, wait, then retry with a growing delay instead of resending straight away. -
Catch a typo early. An
unknown_fieldsreply names a field the endpoint doesn't accept, which usually means a misspelled field name. - Keep a trail. Log the request ID with every failure so support can find the exact request quickly.
Frequently asked questions
Should my code read the message or the error code?
The error code. The message is written for people and its wording can change over time. The code is stable, so it is safe to branch on. Show the message to a person if you like, but let the code decide what your software does.
What does a 422 tell me?
That something in your request isn't valid, and nothing was changed. With validation_failed, the response lists each field that failed so you can correct it and resend. A 422 can also mean a filter or sort the object doesn't support.
What should I do when I get a 429?
Pause, then retry with a growing delay, and fetch less per request. A 429 means your key or your account went over an allowance. Build integrations that stay fast and efficient explains the allowances and how to stay under them.
Is a 409 an error?
A 409 with the code decision_required is a question, not a failure. TripWorks needs a choice from you before it can finish, and nothing was changed. How decisions work in the REST API explains how to answer it.
Where do I find the request ID for a failed request?
Every request has an ID that you can look up on the Logs tab of the REST API card, by pasting it into Find by request ID. Quote it when you contact TripWorks support so they can see exactly what was sent and returned.
Related
- How decisions work in the REST API
- Get started with the REST API
- Build integrations that stay fast and efficient
- How API keys and access work
Built for attractions, tours & activities
Build on top of your booking data
See how attractions, tours, and activities connect their booking data to the tools they already use with TripWorks. Book a demo and make the switch.