Table of Contents
< All Topics

API Error Codes and Troubleshooting Guide

Understanding API Errors

The Coext External API uses a consistent error format across all endpoints. Understanding these errors will help you build robust integrations that handle failures gracefully.

Standard Error Response Format

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable description of the error",
    "details": {
      // Additional context (varies by error type)
    }
  },
  "meta": {
    "request_id": "req_abc123def456ghi789"
  }
}
            

Key Fields:

  • success: Always false for errors
  • error.code: Machine-readable error identifier (use this for programmatic handling)
  • error.message: Human-readable description
  • error.details: Additional context specific to the error type
  • meta.request_id: Unique ID for this request (helpful for support)

Authentication Errors (HTTP 401)

These errors occur when the API cannot verify your identity.

Error CodeDescriptionResolution
INVALID_API_KEYAPI key not found in the system or has invalid format
  • Verify API key is correct (check for typos)
  • Ensure key starts with pk_live_
  • Confirm key hasn’t been deleted
EXPIRED_API_KEYAPI key has passed its expiration dateCreate a new API key or remove the expiration date from the existing key
REVOKED_API_KEYAPI key was manually revoked by an administratorCreate a new API key; revoked keys cannot be reactivated
SUSPENDED_API_KEYAPI key is temporarily suspended due to abuse or billing issuesContact support to resolve the suspension
IP_NOT_ALLOWEDRequest originates from an IP address not in the whitelistAdd your server’s IP to the allowed list in key settings
INVALID_SIGNATUREHMAC signature verification failed (only when using enhanced auth)Review signature generation algorithm; ensure JSON serialization matches
TIMESTAMP_EXPIREDRequest timestamp is more than 5 minutes old or in the futureSync your server clock with NTP; use fresh timestamps

Example: INVALID_API_KEY Error

{
  "success": false,
  "error": {
    "code": "INVALID_API_KEY",
    "message": "The provided API key is invalid"
  },
  "meta": {
    "request_id": "req_xyz789"
  }
}
            

Permission Errors (HTTP 403)

These errors occur when your API key doesn’t have the required permissions.

Error CodeDescriptionResolution
PERMISSION_DENIEDAPI key lacks the required permission for this operationEdit the API key and enable the required permission
ACCOUNT_NOT_ACTIVEThe linked WhatsApp Business Account is inactiveReactivate the WhatsApp account in the dashboard

Required Permissions by Endpoint

EndpointRequired Permission
POST /messages/textsend_text
POST /messages/templatesend_template
POST /messages/template/sendsend_template
POST /messages/mediasend_media
GET /templatesview_templates
GET /messages/:uuidview_messages

Rate Limiting Errors (HTTP 429)

These errors occur when you exceed your API usage limits.

Error CodeDescriptionResolution
RATE_LIMIT_EXCEEDEDToo many requests in the current minuteWait for retry_after seconds, then retry with backoff
DAILY_LIMIT_EXCEEDEDDaily request quota has been reachedWait until the next day or request a limit increase

Rate Limit Error Response

{
  "success": false,
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Rate limit exceeded. Please wait before making more requests.",
    "details": {
      "retry_after": 45
    }
  },
  "meta": {
    "request_id": "req_rate123",
    "rate_limit": {
      "limit": 60,
      "remaining": 0,
      "reset_at": "2025-12-19T10:01:00.000Z"
    }
  }
}
            

Implementing Rate Limit Handling

async function sendWithRateLimitHandling(payload) {
  const response = await fetch(url, options);
  
  if (response.status === 429) {
    const data = await response.json();
    const retryAfter = data.error?.details?.retry_after || 60;
    
    console.log(`Rate limited. Waiting ${retryAfter} seconds...`);
    await sleep(retryAfter * 1000);
    
    // Retry the request
    return sendWithRateLimitHandling(payload);
  }
  
  return response;
}

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
            

Validation Errors (HTTP 400)

These errors occur when your request data is invalid or incomplete.

Error CodeDescriptionResolution
VALIDATION_ERRORRequest body validation failed on one or more fieldsCheck error.details.fields for specific issues
INVALID_PHONE_NUMBERPhone number is not in valid E.164 formatUse format: +[country code][number] (e.g., +919876543210)
TEMPLATE_NOT_FOUNDTemplate name doesn’t exist or isn’t approvedVerify template name and approval status
TEMPLATE_NOT_CONFIGUREDTemplate variable mapping not set up for this API keyConfigure template in the dashboard Templates tab
INVALID_TEMPLATE_PARAMSTemplate parameters don’t match expected formatCheck parameter count, types, and positions
MISSING_REQUIRED_VARIABLEA required template variable was not providedInclude all required variables in request

Validation Error with Field Details

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": {
      "fields": {
        "to": "Phone number must be in E.164 format (e.g., +919876543210)",
        "message": "Message is required and cannot be empty"
      }
    }
  },
  "meta": {
    "request_id": "req_val456"
  }
}
            

Message Delivery Errors (HTTP 400/500)

These errors occur during message sending or delivery.

Error CodeDescriptionResolution
MESSAGE_SEND_FAILEDFailed to send message via WhatsAppCheck details.whatsapp_error_code for specifics
MESSAGE_NOT_FOUNDRequested message ID doesn’t existVerify the message UUID is correct

WhatsApp-Specific Error Codes

When messages fail through WhatsApp, you’ll receive specific error codes from Meta:

WA CodeDescriptionResolution
131047Re-engagement message requiredCustomer hasn’t messaged in 24 hours; use a template message instead
13047224-hour customer service window has closedUse an approved template message to re-initiate conversation
131051Unsupported message typeCheck message format is supported by WhatsApp
131052Media URL is expired or invalidProvide a fresh, publicly accessible media URL
368Temporarily blocked for policy violationReview Meta Business messaging policies
80007Rate limit hit on WhatsApp sideSlow down message sending; implement backoff
131026Recipient number not on WhatsAppVerify recipient has WhatsApp installed

WhatsApp Error Response Example

{
  "success": false,
  "error": {
    "code": "MESSAGE_SEND_FAILED",
    "message": "Failed to send message",
    "details": {
      "whatsapp_error_code": 131047,
      "whatsapp_error_message": "Re-engagement message required. Outside 24-hour customer service window."
    }
  },
  "meta": {
    "request_id": "req_wa789"
  }
}
            

Server Errors (HTTP 500/503)

Error CodeDescriptionResolution
INTERNAL_ERRORUnexpected server error occurredRetry with exponential backoff; contact support if persistent
SERVICE_UNAVAILABLEService is temporarily unavailableRetry after a few minutes

Implementing Robust Error Handling

Comprehensive Retry Logic

async function sendMessageWithRetry(payload, maxRetries = 3) {
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      const response = await sendMessage(payload);
      
      if (response.success) {
        return response;
      }
      
      const errorCode = response.error?.code;
      
      // Don't retry client errors (except rate limits)
      if (!shouldRetry(errorCode)) {
        throw new ApiError(errorCode, response.error?.message);
      }
      
      // Handle rate limits specially
      if (errorCode === 'RATE_LIMIT_EXCEEDED') {
        const retryAfter = response.error?.details?.retry_after || 60;
        await sleep(retryAfter * 1000);
        continue;
      }
      
      // Exponential backoff for other retryable errors
      const delay = Math.pow(2, attempt) * 1000;
      console.log(`Retry attempt ${attempt} after ${delay}ms`);
      await sleep(delay);
      
    } catch (error) {
      if (attempt === maxRetries) {
        throw error;
      }
    }
  }
  
  throw new Error('Max retries exceeded');
}

function shouldRetry(errorCode) {
  const retryableCodes = [
    'RATE_LIMIT_EXCEEDED',
    'INTERNAL_ERROR',
    'SERVICE_UNAVAILABLE'
  ];
  return retryableCodes.includes(errorCode);
}
            

Error Code Switch Handler

function handleApiError(error) {
  const code = error.code;
  const details = error.details;
  
  switch (code) {
    case 'INVALID_API_KEY':
    case 'EXPIRED_API_KEY':
    case 'REVOKED_API_KEY':
      console.error('Authentication failed - check your API credentials');
      // Alert operations team
      break;
    
    case 'PERMISSION_DENIED':
      console.error('Missing permission - update API key settings');
      break;
    
    case 'RATE_LIMIT_EXCEEDED':
      console.warn(`Rate limited. Retry after ${details?.retry_after}s`);
      // Queue for delayed retry
      break;
    
    case 'INVALID_PHONE_NUMBER':
      console.error('Bad phone number format');
      // Mark contact as invalid
      break;
    
    case 'MESSAGE_SEND_FAILED':
      const waCode = details?.whatsapp_error_code;
      if (waCode === 131047 || waCode === 130472) {
        console.log('24-hour window closed - need template message');
        // Switch to template sending
      }
      break;
    
    default:
      console.error(`Unhandled error: ${code}`);
  }
}
            

HTTP Status Code Quick Reference

StatusMeaningShould Retry?Action
200SuccessN/AProcess response data
400Bad RequestNoFix request data
401UnauthorizedNoFix authentication
403ForbiddenNoUpdate permissions
404Not FoundNoVerify resource exists
429Rate LimitedYesWait and retry with backoff
500Server ErrorYesRetry with exponential backoff
503UnavailableYesRetry after delay

Getting Help

If you encounter persistent errors that you can’t resolve:

  1. Note the request_id from the error response
  2. Check the Webhook Logs in the dashboard for delivery issues
  3. Review API Key permissions and status
  4. Verify template configuration if using templates
  5. Contact support with the request_id and error details

Leave a Reply

Your email address will not be published. Required fields are marked *