Error codes
Every failure carries a machine-readable code. Switch on the code, never on the message.
The shape
A refused request answers with the HTTP status and a body naming what went wrong:
{
"error": {
"code": "CHANNEL_NOT_LINKED",
"message": "channel Main is linking, so it cannot send. Link or resume it from the console first."
}
}code is the contract and will not change under you. message is written for a human reading a log and is free to be rewritten, so parsing it is how your integration breaks on a Tuesday for no reason you can see.
switch pigeon.ErrorCode(err) {
case pigeon.CodeRecipientNotOnWhatsapp:
// nothing to retry; this person has no WhatsApp
case pigeon.CodeOutsideCustomerServiceWindow:
// send an approved template instead
case pigeon.CodeRateLimited:
time.Sleep(pigeon.RetryAfter(err))
}Every code
| Code | HTTP | What to do | What it means |
|---|---|---|---|
INVALID_API_KEY | 401 | Fix the request | The key is not one Pigeon issued, or it was not sent whole. Include the pgn_live_ or pgn_test_ prefix. The whole string is the key. |
API_KEY_REVOKED | 401 | Fix the request | The key was valid and has been revoked. Someone revoked it in the console. Mint a new one; this will never work again. |
API_KEY_FORBIDDEN_ROLE | 403 | Fix the request | The key is valid but its role does not allow this operation. A send key cannot read the message log, and a read key cannot send. This is deliberate: a credential that leaks from a server which only sends should not also expose every message the project has exchanged. |
PROJECT_INACTIVE | 403 | Fix the request | The project is not active, so it accepts no calls on either environment. |
VALIDATION_ERROR | 422 | Fix the request | A field is missing or malformed. The message names the field. Sending it again unchanged will fail again. |
NOT_FOUND | 404 | Fix the request | No such message on this project. |
PLAN_LIMIT_REACHED | 402 | Read the note | The project has used its monthly message allowance. Not the same as RATE_LIMITED, and the difference matters. Rate limiting says slow down and try again shortly; this says the month is spent and waiting will not help until the plan changes. The message says how many of how many have been used. |
RATE_LIMITED | 429 | Back off, then retry | This API key is sending faster than its budget allows. Read Retry-After. Guessing is how a client that is already too fast stays too fast. |
CHANNEL_NOT_FOUND | 404 | Fix the request | No channel with that id on this project. |
CHANNEL_NOT_LINKED | 409 | Fix the request | The channel exists but is not connected to WhatsApp. Link or resume it in the console. On OpenWA that means scanning a QR code; the number may also have been logged out from the phone. |
CHANNEL_PACING_EXCEEDED | 429 | Back off, then retry | This number has sent as much as Pigeon will let it today. Not an API limit: it protects the NUMBER. A new number ramps up over 14 days, and cold outreach is capped separately from replies, because WhatsApp bans on pattern as much as on volume. |
CHANNEL_RESTRICTED | 409 | Read the note | Pigeon has parked this channel after repeated terminal failures. The breaker tripped. Something is wrong with the number itself; look at it in the console before resuming. |
RECIPIENT_NOT_ON_WHATSAPP | 422 | Fix the request | That number has no WhatsApp account. Nothing to retry. Reach them another way. |
RECIPIENT_SUPPRESSED | 409 | Fix the request | This person opted out, or a previous message to them hard-failed. Pigeon enforces this rather than trusting the caller to remember. Remove them from the suppression list only if they opted back in. |
OUTSIDE_CUSTOMER_SERVICE_WINDOW | 409 | Fix the request | More than 24 hours since this person last wrote to you. Meta's rule, enforced before the request reaches them so the error is readable. Send an approved template instead. |
TEMPLATE_REQUIRED | 409 | Fix the request | This message needs a template and none was given. |
TEMPLATE_NOT_APPROVED | 409 | Back off, then retry | The template exists but Meta has not approved it. Approval is Meta's, not Pigeon's. Check its status in the console. |
MEDIA_TOO_LARGE | 413 | Fix the request | The attachment is larger than WhatsApp accepts. |
MEDIA_TYPE_UNSUPPORTED | 415 | Fix the request | WhatsApp does not accept that file type. |
PROVIDER_UNAVAILABLE | 503 | Safe to retry | Pigeon could not reach the provider. Nothing was sent. Retrying is safe. |
PROVIDER_RATE_LIMITED | 429 | Back off, then retry | The provider is throttling, not Pigeon. |
PROVIDER_ERROR | 502 | Read the note | The provider refused the message and said why. The message carries the provider's own reason. Whether to retry depends on it. |
OUTCOME_UNKNOWN | 502 | Read the note | Pigeon does not know whether the message was sent. The provider accepted the request and then the connection died, or Pigeon could not reach it after handing the message over. The message may be on its way to a real phone. Resend with the SAME idempotency key: Pigeon returns the existing message if the first attempt landed, and sends it if it did not. Resending without one is how somebody receives it twice. |
This table is checked against the server by a test: every code listed here must exist in the API, so a code renamed in the server fails the build rather than quietly becoming a lie on this page.
Idempotency & retries
Which failures are safe to retry, and how.
Choosing a provider
Why some of these errors only happen on one of them.