Errors
Error codes returned by the MessageOS API.
Every error uses one body:
{ "error": { "code": "validation_error", "message": "Attributes are not valid.", "requestId": "req_3f2a9c1d7e5b4a60", "details": [{ "path": "tier", "message": "Unknown key" }] } }code is stable. message is for people and can change. details lists field problems when there are any, each with the path of the field. A blocked error also has reason.
| Code | Status | Meaning |
|---|---|---|
unauthorized | 401 | The key is missing, unknown, expired, or revoked |
forbidden | 403 | The key does not have the scope, or this send is not allowed |
not_found | 404 | Missing, hidden from this caller, or a feature that is not enabled |
conflict | 409 | The request conflicts with stored data, a request with the same key is still in progress, or the messaging network would not take a message back |
blocked | 409 | Nothing was sent or shown. reason says why, and message says what to do |
payload_too_large | 413 | The request body is over the size limit, 1 MB |
validation_error | 422 | The body, a query value, or a header is not valid, or the body is not JSON |
idempotency_key_reuse | 422 | POST /v1/messages, POST /v1/knowledge, or POST /v1/events got a key it already saw with a different body |
rate_limited | 429 | Over a per-minute request limit. MessageOS does not cap requests, so this is answered only if a limit has been set. Retry-After is in seconds |
internal_error | 500 | The request could not be completed |
provider_unavailable | 503 | The messaging network did not answer a capability check, a typing indicator, or a request to take a message back, or was busy or over its limit. Try again in a moment. A send never answers this: a send the network did not take is blocked |
service_unavailable | 503 | MessageOS could not complete the request just now. Retry-After is the number of seconds to wait before sending it again |
An unexpected failure returns 500 internal_error in the same shape, with a request id.
A 500 or a 503 can be sent again. Use the same Idempotency-Key and the same body, and wait the seconds in Retry-After first when the answer has that header. However often you retry, at most one message is sent. Idempotency says what a retry can answer.
A body field clientId or optedIn is rejected. Only a message from the person changes opt-in.
Why a message was blocked
A send that did not go out returns 409 with code blocked. reason is the stable cause, and message says the same in a sentence, with what to do next:
{ "error": { "code": "blocked", "reason": "opted_out", "message": "This person opted out. Nothing was sent. Only a message from them opts them back in.", "requestId": "req_3f2a9c1d7e5b4a60", "details": [{ "path": "reason", "message": "opted_out" }] } }Branch on reason. details[0].message repeats it. The words of message can change.
reason | What message says | The same Idempotency-Key again |
|---|---|---|
opted_out | This person opted out. Nothing was sent. Only a message from them opts them back in. | Gets this answer again |
org_opted_out | This person opted out of this organization's messages. Nothing was sent. | Gets this answer again |
no_consent_record | There is no consent record for this person, and they have not written in. Nothing was sent. Add consent to the request, or store it on the contact, then send again with a new Idempotency-Key. | Gets this answer again |
class_not_allowed | This agent does not send that class of message. Nothing was sent. GET /v1/whoami lists the classes it sends. | Gets this answer again |
template_required | This class of message needs a template for this agent. Nothing was sent. Send it again with template instead of text, with a new Idempotency-Key. | Gets this answer again |
quiet_hours | It is quiet hours for this person. Nothing was sent. Send again when they end, with a new Idempotency-Key. Set onQuiet to defer to learn when that is. | Gets this answer again |
missing_timezone | Quiet hours could not be checked because neither the contact nor the agent has a time zone. Nothing was sent. Set the contact's timezone, then send again with a new Idempotency-Key. | Gets this answer again |
rate_limited_contact | MessageOS has set a limit on how many messages one person receives, and this person has reached it for now. Nothing was sent. Send again later with a new Idempotency-Key. | Gets this answer again |
rate_limited_client | MessageOS has set a limit on how many messages one agent sends, and this agent has reached it for now. Nothing was sent. Send again later with a new Idempotency-Key. | Gets this answer again |
duplicate | The same message was sent to this person a moment ago. Nothing was sent. | Gets this answer again |
invalid_content | The message has no content. Nothing was sent. | Gets this answer again |
contact_not_found | That contact no longer exists. Nothing was sent. | Gets this answer again |
agent_paused | This agent is paused. Nothing was sent. | Gets this answer again |
human_handled | A person is handling this conversation. Nothing was sent. | Gets this answer again |
agent_not_available | This agent cannot message this phone number yet. Nothing was sent. An agent that has not launched reaches only its testers, and an agent that is still being set up reaches no one. Ask MessageOS if this agent should be able to reach this number. | Sends the message again |
message_rejected | The messaging network did not accept this message. Nothing was sent. The phone number may not be a mobile number it can reach, or the content may not be valid. Check both before sending again. | Sends the message again |
provider_busy | The messaging network is busy or over its limit. Nothing was sent. Wait, then send again with the same Idempotency-Key. | Sends the message again |
provider_error | The messaging network did not confirm this message, so it is not reported as sent. It may still have gone out. You can send again with the same Idempotency-Key, and if the first one did go out the person gets it twice. | Sends the message again |
The last column says what the same Idempotency-Key and body get the next time. Most blocked answers are kept for the key, so a retry with it gets the same answer and nothing is tried again. To send again after quiet hours end or you add consent, use a new key.
A few of these need more than the sentence:
no_consent_record: a message you start needs a consent record for the person, or an earlier message from them. A phone number that is not yet a contact gets this reason too. Sendconsentin the same request and the contact is created with it. A reply sent withinReplyToneeds none.quiet_hoursandmissing_timezone: these apply whereGET /v1/whoamishowsquietHoursEnforcedtrue, or when the request setsonQuiettorejectordefer. A reply sent withinReplyTois not held.class_not_allowed:POST /v1/messagesdoes not answer with this reason. A class your agent does not send is refused before the send rules run, with 422validation_error, anddetails[0].pathisclass.allowedClassesinGET /v1/whoamilists the classes it sends.class_not_allowedis the reason when a draft is approved and its class is not one the agent sends.rate_limited_contactandrate_limited_client: MessageOS does not cap how many messages you send, so a send gets one of these only if a send limit has been set.limitsinGET /v1/whoamiis null for each limit that is not set. Rate limits says what a limit counts.duplicate: a send with its ownIdempotency-Keyis not checked for repeated words. This reason is for an approved draft.agent_paused: only an event playbook message, such as an approved playbook draft, is held by a pause. Messages you send yourself are not.agent_not_available,message_rejected,provider_busy, andprovider_error: the messaging network did not take the message, or forprovider_errordid not confirm it. The answer is not kept for theIdempotency-Key, so the same key sends again. Afterprovider_errorthe first message may have gone out, so sending again can reach the person twice.provider_busy: the answer has aRetry-Afterheader. Wait that many seconds, then send again with the sameIdempotency-Key.
A repeat of POST /v1/messages with the same Idempotency-Key while the first request is still running is not a blocked answer. It answers 409 conflict with Retry-After: 1.
A message that was sent and then could not be delivered is not an error on the request. It arrives as the message.failed event, and GET /v1/messages/{id} shows failed.
Approving a draft can also return 403 forbidden with the reason test_session in details[0].message. The draft was written in a MessageOS test session, so it cannot be sent to the person. Nothing was delivered, and the draft is marked blocked.
