Error Codes
API errors return a JSON body with an error string and, on endpoints that define one, a code field. Rate-limited responses include retry_after_seconds in the body. Rate limiting does not set Retry-After headers, except magic-link status polling and OTP-send 429 responses.
Error response format
// HTTP 429 — API-key rate limit
{
"error": "Rate limit exceeded",
"limit": 1000,
"window": "1 hour",
"retry_after_seconds": 3600
}
// HTTP 400 — wrong OTP code
{
"valid": false,
"error": "invalid_code",
"attempts_remaining": 3
}
// HTTP 403 — missing scope
{
"error": "Insufficient scope. Required: contacts:write"
}HTTP status codes
| Status | Meaning | Typical error values | Retry? |
|---|---|---|---|
| 400 | Missing or invalid request body, phone format, template, or OTP code | invalid_phone, missing_fields, invalid_code | No |
| 401 | Missing, invalid, or expired API key | Missing or invalid API key | No |
| 403 | The key lacks the required scope, or the package is inactive | Insufficient scope. Required: contacts:write | No |
| 404 | The resource does not exist in this workspace | Contact not found | No |
| 409 | Duplicate resource or a request that conflicts with current state | Contact already exists | No |
| 429 | A request or OTP limit was exceeded | retry_after_seconds is included in the body | Yes |
| 500 | Unexpected server error | Internal failure | Yes |
| 503 | A dependency or provider is temporarily unavailable | Provider outcome unknown; do not resend automatically | Yes |
WhatsApp OTP — send errors
| code | HTTP | Description |
|---|---|---|
| invalid_phone | 400 | Phone is not valid E.164 |
| invalid_sender | 400 | The selected WhatsApp number is not valid for this workspace |
| invalid_code_source | 400 | code_source must be platform or client |
| invalid_client_code | 400 | Client code must be 4–15 ASCII letters or digits |
| otp_assignment_override | 400 | A project key tried to override its assigned sender or template |
| module_inactive | 403 | The WhatsApp package is not active |
| otp_assignment_unavailable | 409 | The assigned project sender or template is not ready |
| rate_limit_exceeded | 429 | More than 5 OTPs to the same phone in 10 minutes |
| workspace_limit_exceeded | 429 | More than 1,000 OTPs for the workspace in one hour |
| project_limit_exceeded | 429 | More than 250 OTPs for the project in one hour |
| test_limit_exceeded | 429 | More than 10 test OTPs for the workspace in one hour |
| delivery_failed | 503 | WhatsApp did not accept the OTP and SMS fallback was unavailable |
| otp_unavailable | 503 | OTP capacity or delivery could not be confirmed; retry |
WhatsApp OTP — verify errors
A failed verification returns valid: false plus the error value below. A correct code returns HTTP 200 with valid: true.
| error | HTTP | Description |
|---|---|---|
| invalid_request | 400 | request_id is missing or not a UUID |
| invalid_code | 400 | Wrong code; attempts_remaining is included |
| max_attempts_exceeded | 400 | 5 failed attempts — the request is permanently invalidated |
| expired | 400 | The 10-minute TTL has passed |
| already_verified | 400 | This request was already verified once |
| delivery_unavailable | 400 | The OTP was never successfully delivered |
| verification_in_progress | 409 | Another verification for this request is still in flight |
| verification_unavailable | 503 | The verification result could not be saved; retry |
WhatsApp messaging — send errors
| code | HTTP | Description |
|---|---|---|
| missing_fields | 400 | Required to/template or to/text fields are missing |
| invalid_phone | 400 | Phone is not valid E.164 |
| template_not_approved | 400 | The template is not APPROVED in Meta |
| text_too_long | 400 | Free-form text exceeds 4,096 characters |
| module_inactive | 403 | The WhatsApp package is not active |
| send_preflight_failed | 409 | Pre-send validation failed; review the message and retry |
| phone_rate_limited | 429 | More than 5 messages to the same phone in one hour |
| no_wa_number | 503 | No verified WhatsApp sender is available |
| meta_error | 503 | Meta rejected the message; details explain why |
| submission_unknown | 503 | Provider outcome unknown; do not resend automatically |
Handling errors in the SDK
import { createClient, OutreachAgentError } from '@emacrontechnologies/outreachagent';
const oa = createClient(process.env.OUTREACHAGENT_API_KEY!);
try {
const { valid } = await oa.otp.verify(requestId, code);
if (!valid) {
// Defensive only: the SDK throws on HTTP 400, so a wrong code reaches catch.
return res.json({ success: false, message: 'Incorrect OTP' });
}
// ✅ valid === true — log the user in
} catch (err) {
if (err instanceof OutreachAgentError) {
if (err.status === 400) {
// The API puts the reason in the body's `error` field. The SDK exposes
// it as `message`; `code` is UNKNOWN when the endpoint has no code field.
return res.status(400).json({ message: err.message });
}
if (err.status === 429) {
const retryAfter = (err.raw as { retry_after_seconds?: number })?.retry_after_seconds;
return res.status(429).json({ message: 'Rate limit hit', retry_after_seconds: retryAfter });
}
console.error('EmacronAI CRM error:', err.status, err.code, err.message);
return res.status(err.status >= 500 ? 503 : 400).json({ message: 'Verification failed' });
}
throw err; // re-throw non-EmacronAI CRM errors
}