Skip to content

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

StatusMeaningTypical error valuesRetry?
400Missing or invalid request body, phone format, template, or OTP codeinvalid_phone, missing_fields, invalid_codeNo
401Missing, invalid, or expired API keyMissing or invalid API keyNo
403The key lacks the required scope, or the package is inactiveInsufficient scope. Required: contacts:writeNo
404The resource does not exist in this workspaceContact not foundNo
409Duplicate resource or a request that conflicts with current stateContact already existsNo
429A request or OTP limit was exceededretry_after_seconds is included in the bodyYes
500Unexpected server errorInternal failureYes
503A dependency or provider is temporarily unavailableProvider outcome unknown; do not resend automaticallyYes

WhatsApp OTP — send errors

codeHTTPDescription
invalid_phone400Phone is not valid E.164
invalid_sender400The selected WhatsApp number is not valid for this workspace
invalid_code_source400code_source must be platform or client
invalid_client_code400Client code must be 4–15 ASCII letters or digits
otp_assignment_override400A project key tried to override its assigned sender or template
module_inactive403The WhatsApp package is not active
otp_assignment_unavailable409The assigned project sender or template is not ready
rate_limit_exceeded429More than 5 OTPs to the same phone in 10 minutes
workspace_limit_exceeded429More than 1,000 OTPs for the workspace in one hour
project_limit_exceeded429More than 250 OTPs for the project in one hour
test_limit_exceeded429More than 10 test OTPs for the workspace in one hour
delivery_failed503WhatsApp did not accept the OTP and SMS fallback was unavailable
otp_unavailable503OTP 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.

errorHTTPDescription
invalid_request400request_id is missing or not a UUID
invalid_code400Wrong code; attempts_remaining is included
max_attempts_exceeded4005 failed attempts — the request is permanently invalidated
expired400The 10-minute TTL has passed
already_verified400This request was already verified once
delivery_unavailable400The OTP was never successfully delivered
verification_in_progress409Another verification for this request is still in flight
verification_unavailable503The verification result could not be saved; retry

WhatsApp messaging — send errors

codeHTTPDescription
missing_fields400Required to/template or to/text fields are missing
invalid_phone400Phone is not valid E.164
template_not_approved400The template is not APPROVED in Meta
text_too_long400Free-form text exceeds 4,096 characters
module_inactive403The WhatsApp package is not active
send_preflight_failed409Pre-send validation failed; review the message and retry
phone_rate_limited429More than 5 messages to the same phone in one hour
no_wa_number503No verified WhatsApp sender is available
meta_error503Meta rejected the message; details explain why
submission_unknown503Provider 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
}

Next steps