Skip to content

Resend SMS Messages

This endpoint allows you to resend SMS messages that were previously sent. This is particularly useful for messages that failed to deliver or when you need to send the same message again to the same recipients.

Endpoint

POST /sms/resend

Authentication

All requests must include your API token in the header:

X-Huduma: Bearer {your_api_token}

Request Body

ParameterTypeRequiredDescription
smsIdsarray of numbersYesArray of SMS message IDs to resend

Example Request Body

json
{
  "smsIds": [123456, 789012, 345678]
}

Response

Success Response (202 Accepted)

A successful request returns a JSON response with the following structure:

json
{
  "status": "202 ACCEPTED",
  "code": 0,
  "message": "SMS messages queued for resending",
  "timestamp": "2025-04-10T08:24:21.073Z",
  "reqId": "req-123456789",
  "path": "/sms/resend",
  "data": [
    {
      "id": 123456,
      "senderId": "COMPANY",
      "recipient": "255712345678",
      "message": "Your verification code is 123456",
      "credits": 1,
      "schedule": null,
      "status": "QUEUED",
      "smscId": "sms-987654321",
      "callbackUrl": "https://your-website.com/sms-callbacks",
      "thirdPartyRef": "verify-123456",
      "addedBy": {
        "id": 1234,
        "uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "firstName": "API",
        "lastName": "User",
        "gender": "N/A",
        "email": "user@example.com",
        "phone": "255712345678",
        "address": ""
      },
      "createdAt": "2025-04-10T08:15:00.000Z",
      "updatedAt": "2025-04-10T08:24:21.073Z"
    },
    {
      "id": 789012,
      "senderId": "COMPANY",
      "recipient": "255787654321",
      "message": "Your order #54321 has been shipped",
      "credits": 1,
      "schedule": null,
      "status": "QUEUED",
      "smscId": "sms-876543210",
      "callbackUrl": "https://your-website.com/sms-callbacks",
      "thirdPartyRef": "order-54321",
      "addedBy": {
        "id": 1234,
        "uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "firstName": "API",
        "lastName": "User",
        "gender": "N/A",
        "email": "user@example.com",
        "phone": "255712345678",
        "address": ""
      },
      "createdAt": "2025-04-10T07:30:00.000Z",
      "updatedAt": "2025-04-10T08:24:21.073Z"
    }
  ]
}

Error Responses

Status CodeDescription
400Bad Request - Invalid parameters or empty SMS IDs array
401Unauthorized - Invalid or missing API token
402Payment Required - Insufficient credits
403Forbidden - Insufficient permissions
404Not Found - One or more SMS messages not found
405Method Not Allowed - Invalid HTTP method
422Unprocessable Entity - Invalid input parameters
500Internal Server Error - Server-side error

Error Response Format

json
{
  "status": "404 NOT FOUND",
  "code": 4040,
  "message": "One or more SMS messages not found",
  "timestamp": "2025-04-10T08:24:21.079Z",
  "reqId": "req-123456789",
  "path": "/sms/resend",
  "errors": [
    {
      "field": "smsIds",
      "message": "SMS with ID 999999 not found",
      "rejectedValue": 999999,
      "rejectingValues": {}
    }
  ]
}

Code Examples

TypeScript Example

typescript
import axios from 'axios';

interface ResendSMSRequest {
  smsIds: number[];
}

interface ResendSMSResponse {
  status: string;
  code: number;
  message: string;
  timestamp: string;
  reqId: string;
  path: string;
  data: Array<{
    id: number;
    senderId: string;
    recipient: string;
    message: string;
    credits: number;
    schedule: string | null;
    status: string;
    smscId: string;
    callbackUrl: string | null;
    thirdPartyRef: string | null;
    addedBy: {
      id: number;
      uuid: string;
      firstName: string;
      lastName: string;
      gender: string;
      email: string;
      phone: string;
      address: string;
    };
    createdAt: string;
    updatedAt: string;
  }>;
}

async function resendSMS(
  apiToken: string,
  smsIds: number[]
): Promise<ResendSMSResponse> {
  if (!smsIds.length) {
    throw new Error('At least one SMS ID must be provided');
  }
  
  try {
    const response = await axios.post(
      'https://sms-api.huduma.cloud/api/v3/sms/resend',
      { smsIds },
      {
        headers: {
          'X-Huduma': `Bearer ${apiToken}`,
          'Content-Type': 'application/json',
          'Accept': 'application/json'
        }
      }
    );
    
    return response.data;
  } catch (error) {
    console.error('Error resending SMS:', error);
    throw error;
  }
}

// Example usage
const apiToken = 'your_api_token_here';
const messagesToResend = [123456, 789012, 345678];

resendSMS(apiToken, messagesToResend)
  .then(response => {
    console.log(`${response.data.length} SMS messages queued for resending`);
    console.log('Resent messages:', response.data);
  })
  .catch(error => {
    console.error('Failed to resend SMS:', error.response?.data || error.message);
  });

JavaScript Example

javascript
const axios = require('axios');

async function resendSMS(apiToken, smsIds) {
  if (!smsIds.length) {
    throw new Error('At least one SMS ID must be provided');
  }
  
  try {
    const response = await axios.post(
      'https://sms-api.huduma.cloud/api/v3/sms/resend',
      { smsIds },
      {
        headers: {
          'X-Huduma': `Bearer ${apiToken}`,
          'Content-Type': 'application/json',
          'Accept': 'application/json'
        }
      }
    );
    
    return response.data;
  } catch (error) {
    console.error('Error resending SMS:', error);
    throw error;
  }
}

// Example usage
const apiToken = 'your_api_token_here';
const messagesToResend = [123456, 789012, 345678];

resendSMS(apiToken, messagesToResend)
  .then(response => {
    console.log(`${response.data.length} SMS messages queued for resending`);
    console.log('Resent messages:', response.data);
  })
  .catch(error => {
    console.error('Failed to resend SMS:', error.response?.data || error.message);
  });

Additional Notes

  • You can only resend SMS messages that were previously sent from your account.
  • Each resent message will consume credits from your account balance, just like a new message.
  • The original message content, recipient, and sender ID will be used for resending.
  • Messages that were previously failed or undelivered can be resent.
  • You can resend multiple messages in a single API call by including multiple SMS IDs in the request.
  • The system will return a new status for each resent message, and any callback URLs configured for the original messages will be triggered with delivery updates.
  • If any of the provided SMS IDs are not found, the API will return an error and no messages will be resent.
  • Messages with a DELIVERED status can also be resent if needed.