Errors
The developer API has 2 groups of endpoints, and their error bodies are not the same:
- The send endpoint (
POST .../developer/messages), the pre-call context endpoint (GET .../developer/precall_context), and the phone number contact endpoints. Their errors have a stableerrorcode and amessage. - The conversation and contact endpoints. Their errors have a text in
error, or amessageand a list ofattributes.
Send and pre-call context errors
The send and pre-call context endpoints return this body for a 422 and a 404:
error is a stable code for a program. Branch on it. message is for a person who reads your logs. It can change at any time.
422 Unprocessable Entity
The API understood the request but cannot do it.
contact_conflict is strict on purpose. If the API used the contact that has that email address, it would send your message to the phone number of that contact. The API rejects the request instead.
A send can also fail with a 422 that has a message and attributes and no error code. An example is a send with template_params to the Phone inbox, which cannot deliver a message. A send with plain content to the Phone inbox fails first with outside_messaging_window. See Conversation and contact errors.
The phone number contact endpoints (GET .../developer/contacts/by_phone and POST .../developer/contacts/create_or_update) return the same body for a 422. They return 404 with the text body in Conversation and contact errors.
404 Not Found
The conversation_id, contact_id, inbox_id, or phone_number is not in this account. An id from another account gives the same 404. The API never tells you that an id exists in another account.
Conversation and contact errors
The conversation, label, assignment, and contact endpoints return these bodies.
A 404 has 1 fixed text:
A 422 for a field that is not valid has a message and the names of the fields. An example is an email address that another contact has:
A 422 for a filter that is not valid, or for a message that the API cannot create, has the reason in error:
401 Unauthorized
The API returns 401 for all authentication and account failures. It has no separate 403. When the request has a token, the body has only the error field:
A request with no api_access_token header also returns 401. Its body is a sign-in error with a different shape, not an error field.
A key reaches the whole account that created it: every inbox, conversation, and contact. It reaches nothing in other accounts.
Keep a key as secret as a password. Create 1 key for each integration, so that you can revoke 1 key and keep the others.
429 Too Many Requests
By default, a key can send 300 requests in 1 minute. The key sent more than its limit. Wait until the next minute. Then try again.
The rate limit applies before the application gets the request. The body is therefore plain text, not JSON: