Tutorials

Send SMS with Node.js and Infobip API

Learn how to send SMS messages using Node.js and the Infobip API. Complete guide covering manual HTTP requests, official SDK integration, API layer setup, error handling, and production deployment.

JH
Jacky Hossein
β€’ Principal Telecommunications Architect β€’ Published Nov 1, 2026 β€’ 14 min read

Developer Quick-Start: Learn how to send SMS messages using Node.js and the Infobip API. Complete guide covering manual HTTP requests, official SDK integration, API layer setup, error handling, and production deployment. Want to skip 10DLC vetting queues, carrier surcharges, and multi-step SDK boilerplate? You can send the same SMS directly via SMSRoute's REST API with instant no-KYC provisioning.

Send SMS messages programmatically using Node.js and the Infobip API. This complete guide shows you how to integrate Infobip SMS functionality into your Node.js application using either manual HTTP requests with Axios or the official Infobip SDK.

You'll learn to set up your Node.js project, authenticate with the Infobip API, send SMS messages using two different approaches, create an Express API endpoint for SMS delivery, implement production-ready error handling, and deploy your SMS service securely. Whether you're building a notification system, two-factor authentication, or marketing campaigns, this guide covers everything you need to send SMS with Node.js and Infobip.

Technologies Used:

  • Node.js: A JavaScript runtime environment for building server-side applications.
  • npm (or yarn): Package managers for Node.js.
  • Infobip API: The communication platform service for sending SMS messages.
  • Axios (Optional): A promise-based HTTP client for making requests manually.
  • @infobip-api/sdk (Optional): The official Infobip Node.js SDK for simplified API interaction.
  • Express (Optional): A minimal web framework for Node.js to create API endpoints.
  • dotenv: A module to load environment variables from a .env file.

You need basic understanding of JavaScript, Node.js, and REST APIs.

Prerequisites

Ensure you have the following before you begin:

  1. Node.js and npm (or yarn): Install Node.js v20 (Iron - Maintenance LTS) or v22 (Jod - Active LTS) on your development machine. Download from nodejs.org. Production applications should use Active LTS or Maintenance LTS versions.
  2. Infobip Account: Sign up for a free trial or use your existing account at infobip.com. Free trial accounts can send SMS only to your verified phone number.
  3. Infobip API Key and Base URL: Get these credentials to authenticate your API requests.

Why Use Infobip for SMS Integration?

Infobip provides a robust SMS API platform for sending transactional and marketing messages at scale. Developers choose Infobip for:

Common Use Cases:

  • Two-Factor Authentication (2FA): Send verification codes for secure login
  • Transactional Notifications: Order confirmations, shipping updates, appointment reminders
  • Marketing Campaigns: Promotional messages and customer engagement
  • Alert Systems: Critical notifications and system alerts

Key Benefits:

  • Global Reach: Send SMS to 190+ countries with carrier connections worldwide
  • High Deliverability: Direct carrier partnerships ensure reliable message delivery
  • Developer-Friendly: RESTful API with official SDKs for Node.js, Python, Java, PHP, and more
  • Scalability: Handle from a few messages to millions per day
  • Delivery Reports: Real-time status updates via webhooks for message tracking

This guide focuses on Node.js integration, but the concepts apply to other programming languages.

Getting Your Infobip API Credentials

Get two key pieces of information from your Infobip account:

  1. API Key: Authenticates your requests.
  2. Base URL: The specific API endpoint domain assigned to your account.

Steps to find your credentials:

  1. Log in to your Infobip account.
  2. Navigate to the homepage dashboard after login.
  3. Find your Base URL prominently displayed (e.g., xxxxx.api.infobip.com).
  4. Click your username or profile icon in the top-right corner.
  5. Look for API Keys or navigate to the Developers section.
  6. View existing API keys or generate a new one. Copy the API Key value securely. Treat this key like a password – never share it publicly or commit it to version control.

Keep these two values handy – you'll use them shortly.

1. Setting up the Project

Create a new Node.js project.

  1. Create Project Directory: Open your terminal and create a new directory for your project, then navigate into it.
   mkdir node-infobip-sms
   cd node-infobip-sms
  1. Initialize Node.js Project: Run npm init and follow the prompts. Accept the defaults by pressing Enter repeatedly, or customize the details. This creates a package.json file.
   npm init -y

(The -y flag accepts all defaults)

  1. Install Core Dependencies: Install dotenv to manage your API credentials securely.
   npm install dotenv

(If using yarn: yarn add dotenv)

  1. Create .gitignore: Prevent committing sensitive information and unnecessary files. Create a file named .gitignore in your project root:
   # .gitignore

   # Dependencies
   node_modules/

   # Environment variables
   .env

   # Log files
   *.log

   # OS generated files
   .DS_Store
   Thumbs.db
  1. Create .env File: Create a file named .env in the project root to store your sensitive Infobip credentials. Add your API Key and Base URL:

.env

   # .env
   INFOBIP_API_KEY=YOUR_API_KEY_HERE
   INFOBIP_BASE_URL=YOUR_BASE_URL_HERE
   # Optional: Your phone number for testing (must be verified for free trial accounts)
   YOUR_VERIFIED_PHONE_NUMBER=YOUR_PHONE_NUMBER_HERE

Important: Replace the placeholder values with your actual Infobip API Key, Base URL, and optionally your verified phone number (include the country code, e.g., +15551234567).

Now your basic project structure is ready.

2. Send SMS Messages with Node.js: Two Approaches

Send SMS using two approaches:

  • Approach 1: Manually construct and send HTTP requests using axios. This provides deeper understanding of the API interaction.
  • Approach 2: Use the official @infobip-api/sdk. This simplifies the process and is recommended for production use.

Approach 1: Send SMS with Axios HTTP Client

Use the axios HTTP client to directly interact with the Infobip Send SMS API endpoint (/sms/2/text/advanced).

  1. Install Axios:
   npm install axios

(If using yarn: yarn add axios)

  1. Create sendManual.js: Create a new file named sendManual.js containing the logic for sending SMS.
   const axios = require('axios');

   const buildUrl = (domain) => {
     if (!domain) {
       throw new Error('Infobip domain (Base URL) is mandatory in config.');
     }

     const cleanDomain = domain.replace(/^https?:\/\//, '');
     return `https://${cleanDomain}/sms/2/text/advanced`;
   };

   const buildHeaders = (apiKey) => {
     if (!apiKey) {
       throw new Error('Infobip API Key is mandatory in config.');
     }
     return {
       'Content-Type': 'application/json',
       'Accept': 'application/json',
       'Authorization': `App ${apiKey}`
     };
   };

   const buildRequestBody = (destinationNumber, message, sender = 'InfoSMS') => {

     if (!/^\+?\d{10,15}$/.test(destinationNumber)) {
        console.warn(`Destination number ""${destinationNumber}"" may not be in the correct international format (e.g., +15551234567).`);

     }
      if (!message || typeof message !== 'string' || message.trim() === '') {
       throw new Error('Message content cannot be empty.');
      }

     const destinationObject = {
       to: destinationNumber
     };
     const messageObject = {
       destinations: [destinationObject],
       text: message,


       from: sender
     };
     return {
       messages: [messageObject]
     };
   };

   const parseSuccessResponse = (axiosResponse) => {
     const responseBody = axiosResponse.data;

     if (!responseBody || !responseBody.messages || responseBody.messages.length === 0) {
         return { success: true, data: responseBody, warning: ""Successful response but no message details found."" };
     }
     const singleMessageResponse = responseBody.messages[0];
     return {
       success: true,
       messageId: singleMessageResponse.messageId,
       status: singleMessageResponse.status.name,
       groupName: singleMessageResponse.status.groupName,
       description: singleMessageResponse.status.description,
       bulkId: responseBody.bulkId
     };
   };

   const parseFailedResponse = (axiosError) => {
     let errorInfo = { success: false, errorMessage: axiosError.message, errorDetails: null, statusCode: null };

     if (axiosError.response) {


       const responseBody = axiosError.response.data;
       errorInfo.statusCode = axiosError.response.status;
       if (responseBody && responseBody.requestError && responseBody.requestError.serviceException) {
         errorInfo.errorMessage = responseBody.requestError.serviceException.text || 'Unknown Infobip service exception';
         errorInfo.errorDetails = responseBody;
       } else {
         errorInfo.errorMessage = `Infobip API Error (Status ${errorInfo.statusCode}): ${axiosError.response.statusText}`;
         errorInfo.errorDetails = responseBody || axiosError.response.statusText;
       }
     } else if (axiosError.request) {

       errorInfo.errorMessage = 'No response received from Infobip API. Check network connectivity or Base URL.';
     } else {

       errorInfo.errorMessage = `Axios request setup error: ${axiosError.message}`;
     }
     return errorInfo;
   };

   const sendSmsManually = async (config, destinationNumber, message) => {
     try {

       if (!config || !config.domain || !config.apiKey) {
           throw new Error('Configuration object with domain and apiKey is required.');
       }
       if (!destinationNumber) throw new Error('destinationNumber parameter is mandatory');
       if (!message) throw new Error('message parameter is mandatory');

       const url = buildUrl(config.domain);
       const requestBody = buildRequestBody(destinationNumber, message);
       const headers = buildHeaders(config.apiKey);

       console.log(`Sending SMS manually to ${destinationNumber} via ${url}`);

       const response = await axios.post(url, requestBody, { headers: headers });
       return parseSuccessResponse(response);

     } catch (error) {
       const parsedError = parseFailedResponse(error);
       console.error('Error sending SMS manually:', parsedError);
       return parsedError;
     }
   };

   module.exports = { sendSmsManually };

Why this structure? Breaking down the logic into smaller, focused functions (URL building, header construction, body construction, response parsing) makes the code cleaner, easier to test, and more maintainable. The main sendSmsManually function orchestrates these steps and handles the overall success/error flow using async/await for better readability. We added basic input validation and more robust error parsing.

  1. Create index.js for Testing: Create a file named index.js in the project root to test the sendManual.js module.
   require('dotenv').config();

   const { sendSmsManually } = require('./sendManual');

   const infobipConfig = {
     domain: process.env.INFOBIP_BASE_URL,
     apiKey: process.env.INFOBIP_API_KEY,
   };

   const recipientPhoneNumber = process.env.YOUR_VERIFIED_PHONE_NUMBER;
   const messageText = `Hello from Node.js (Manual Axios)! Time: ${new Date().toLocaleTimeString()}`;

   if (!infobipConfig.domain || !infobipConfig.apiKey) {
     console.error('ERROR: INFOBIP_BASE_URL and INFOBIP_API_KEY must be set in the .env file.');
     process.exit(1);
   }
   if (!recipientPhoneNumber) {
       console.error('ERROR: YOUR_VERIFIED_PHONE_NUMBER must be set in the .env file for testing.');
       process.exit(1);
   }

   console.log(`Attempting to send SMS to: ${recipientPhoneNumber}`);

   sendSmsManually(infobipConfig, recipientPhoneNumber, messageText)
     .then(result => {
       console.log('Manual Send Result:', JSON.stringify(result, null, 2));
       if(result.success) {
           console.log(`SMS submitted successfully! Message ID: ${result.messageId}, Status: ${result.status}`);
       } else {
           console.error(`SMS sending failed. Error: ${result.errorMessage}`);
       }
     })
     .catch(error => {

       console.error('Unexpected error in index.js:', error);
     });
  1. Run the Test: Execute the index.js file from your terminal:
   node index.js

You should see output indicating the attempt and then either a success message with details or an error message. Check your phone for the SMS! Remember, free trial accounts can typically only send to the phone number used during signup.

Approach 2: Send SMS with Infobip Official Node.js SDK

The official SDK (@infobip-api/sdk) abstracts away the direct HTTP calls, providing a cleaner interface.

  1. Install the SDK:
   npm install @infobip-api/sdk

(If using yarn: yarn add @infobip-api/sdk)

  1. Create sendSdk.js: Create a new file named sendSdk.js.
   const { Infobip, AuthType } = require('@infobip-api/sdk');

   let infobipClient;

   const initializeInfobipClient = (config) => {
       if (!config || !config.domain || !config.apiKey) {
           throw new Error('Configuration object with domain and apiKey is required for SDK initialization.');
       }
        if (!infobipClient) {
            console.log(""Initializing Infobip SDK client..."");
            infobipClient = new Infobip({
                baseUrl: config.domain,
                apiKey: config.apiKey,
                authType: AuthType.ApiKey,
            });
        }
        return infobipClient;
   };

   const sendSmsWithSdk = async (config, destinationNumber, message, sender = 'InfoSDK') => {
      try {
          const client = initializeInfobipClient(config);

          if (!destinationNumber) throw new Error('destinationNumber parameter is mandatory');
          if (!message) throw new Error('message parameter is mandatory');

          if (!/^\+?\d{10,15}$/.test(destinationNumber)) {
               console.warn(`Destination number ""${destinationNumber}"" may not be in the correct international format (e.g., +15551234567).`);
          }

          console.log(`Sending SMS via SDK to ${destinationNumber}`);


          const sendSmsPayload = {
              messages: [{
                  destinations: [{ to: destinationNumber }],


                  from: sender,
                  text: message,
              }],


          };


          const infobipResponse = await client.channels.sms.send(sendSmsPayload);


          const responseData = infobipResponse.data;
           if (!responseData || !responseData.messages || responseData.messages.length === 0) {
              return { success: true, data: responseData, warning: ""Successful response but no message details found."" };
          }
          const singleMessageResponse = responseData.messages[0];
          return {
              success: true,
              messageId: singleMessageResponse.messageId,
              status: singleMessageResponse.status.name,
              groupName: singleMessageResponse.status.groupName,
              description: singleMessageResponse.status.description,
              bulkId: responseData.bulkId
          };

      } catch (error) {
          console.error('Error sending SMS with SDK:', error.response ? JSON.stringify(error.response.data, null, 2) : error.message);

          let errorMessage = error.message;
          let errorDetails = null;
          let statusCode = error.response ? error.response.status : null;

           if (error.response && error.response.data && error.response.data.requestError && error.response.data.requestError.serviceException) {
              errorMessage = error.response.data.requestError.serviceException.text || 'Unknown Infobip SDK service exception';
              errorDetails = error.response.data;
          } else if (error.response && error.response.data) {
               errorMessage = `Infobip SDK Error (Status ${statusCode})`;
               errorDetails = error.response.data;
          }

          return {
              success: false,
              errorMessage: errorMessage,
              errorDetails: errorDetails,
              statusCode: statusCode
          };
      }
   };

   module.exports = { sendSmsWithSdk, initializeInfobipClient };

Why this structure? The SDK simplifies interaction significantly. We initialize the client once (or check if it exists) for efficiency. The sendSmsWithSdk function focuses on building the correct payload structure expected by the SDK method (client.channels.sms.send) and handling its specific response and error formats.

  1. Update index.js for SDK Testing: Modify index.js to use the SDK function.
   require('dotenv').config();

   const { sendSmsWithSdk } = require('./sendSdk');

   const infobipConfig = {
     domain: process.env.INFOBIP_BASE_URL,
     apiKey: process.env.INFOBIP_API_KEY,
   };

   const recipientPhoneNumber = process.env.YOUR_VERIFIED_PHONE_NUMBER;

   const messageText = `Hello from Node.js (Official SDK)! Time: ${new Date().toLocaleTimeString()}`;

   if (!infobipConfig.domain || !infobipConfig.apiKey) {
     console.error('ERROR: INFOBIP_BASE_URL and INFOBIP_API_KEY must be set in the .env file.');
     process.exit(1);
   }
    if (!recipientPhoneNumber) {
       console.error('ERROR: YOUR_VERIFIED_PHONE_NUMBER must be set in the .env file for testing.');
       process.exit(1);
   }

   console.log(`Attempting to send SMS to: ${recipientPhoneNumber} using the SDK`);

   sendSmsWithSdk(infobipConfig, recipientPhoneNumber, messageText)
     .then(result => {
       console.log('SDK Send Result:', JSON.stringify(result, null, 2));
        if(result.success) {
           console.log(`SDK: SMS submitted successfully! Message ID: ${result.messageId}, Status: ${result.status}`);
       } else {
           console.error(`SDK: SMS sending failed. Error: ${result.errorMessage}`);
       }
     })
     .catch(error => {
       console.error('Unexpected error in index.js:', error);
     });
  1. Run the Test:
   node index.js

Again, check your console output and your phone.

Choosing an Approach

  • Manual (axios): Good for learning exactly how the API works, offers maximum control over the request, fewer dependencies if you already use axios. However, it requires more boilerplate code and manual maintenance if the API changes.
  • Official SDK (@infobip-api/sdk): Recommended for most production scenarios. It's easier to use, reduces code volume, handles authentication and request structure internally, and is maintained by Infobip, ensuring compatibility with API updates.

For robustness and ease of maintenance, using the official SDK is generally the preferred approach.

3. Create a REST API Endpoint for SMS Sending (Optional)

Expose SMS functionality via a simple REST API using Express.

  1. Install Express:
   npm install express

(If using yarn: yarn add express)

  1. Create server.js: Create a file named server.js. We'll use the SDK implementation here for brevity.
   require('dotenv').config();
   const express = require('express');
   const { sendSmsWithSdk, initializeInfobipClient } = require('./sendSdk');

   const app = express();
   const port = process.env.PORT || 3000;

   app.use(express.json());

   const infobipConfig = {
       domain: process.env.INFOBIP_BASE_URL,
       apiKey: process.env.INFOBIP_API_KEY,
   };

   if (!infobipConfig.domain || !infobipConfig.apiKey) {
     console.error('FATAL ERROR: INFOBIP_BASE_URL and INFOBIP_API_KEY must be set in the environment variables.');
     process.exit(1);
   }

   try {
       initializeInfobipClient(infobipConfig);
       console.log(""Infobip client initialized successfully."");
   } catch (error) {
       console.error(""FATAL ERROR: Failed to initialize Infobip client:"", error.message);
       process.exit(1);
   }

   app.get('/', (req, res) => {
       res.send('SMS Service is running. Use POST /send to send an SMS.');
   });

   app.post('/send', async (req, res) => {
       const { to, message } = req.body;


       if (!to || !message) {

           return res.status(400).json({ success: false, error: 'Missing required fields: `to` (phone number) and `message`.' });
       }

        if (typeof to !== 'string' || typeof message !== 'string' || message.trim() === '') {
            return res.status(400).json({ success: false, error: 'Invalid input format. `to` and `message` must be non-empty strings.' });
        }

       console.log(`Received request to send SMS to: ${to}`);

       try {

           const result = await sendSmsWithSdk(infobipConfig, to, message);

           if (result.success) {
               console.log(`API: SMS submitted successfully for ${to}. Message ID: ${result.messageId}`);

               res.status(200).json({
                   success: true,
                   messageId: result.messageId,
                   status: result.status,
                   description: result.description
               });
           } else {
               console.error(`API: Failed to send SMS to ${to}. Error: ${result.errorMessage}`, result.errorDetails || '');

               res.status(result.statusCode || 500).json({
                   success: false,
                   error: result.errorMessage || 'Failed to send SMS due to an internal error.',

                   details: process.env.NODE_ENV !== 'production' ? result.errorDetails : undefined
               });
           }
       } catch (error) {

           console.error(`API: Unexpected error processing /send request for ${to}:`, error);
           res.status(500).json({ success: false, error: 'An unexpected server error occurred.' });
       }
   });

   app.listen(port, () => {
       console.log(`SMS API server listening on port ${port}`);
       console.log(`Infobip Base URL configured: ${infobipConfig.domain}`);
   });
  1. Run the Server:
   node server.js

The server will start, typically on port 3000.

  1. Test the API Endpoint: You can use curl or a tool like Postman to send a POST request.

Using curl: Replace YOUR_PHONE_NUMBER with the recipient's number (must be verified for free trial).

   curl -X POST http://localhost:3000/send \
        -H ""Content-Type: application/json"" \
        -d '{
              ""to"": ""YOUR_PHONE_NUMBER"",
              ""message"": ""Hello from the Express API!""
            }'

Expected Response (Success):

   {
     ""success"": true,
     ""messageId"": ""SOME_MESSAGE_ID_FROM_INFOBIP"",
     ""status"": ""PENDING_ACCEPTED"",
     ""description"": ""Message accepted and pending processing.""
   }

Expected Response (Failure - e.g., missing field):

   {
     ""success"": false,
     ""error"": ""Missing required fields: `to` (phone number) and `message`.""
   }

4. Infobip API Authentication and Configuration

The core integration is complete:

  • Configuration: API Key (INFOBIP_API_KEY) and Base URL (INFOBIP_BASE_URL) are stored securely in the .env file and loaded using dotenv.
  • Authentication: Handled either via the Authorization: App YOUR_API_KEY header (manual approach) or automatically by the SDK when configured with AuthType.ApiKey.
  • Dashboard Navigation: As detailed in the ""Getting Your Infobip API Credentials"" section.
  • Environment Variables:
  • INFOBIP\_API\_KEY: Your secret key for API authentication. Obtain from Infobip portal API Keys section. Format: String.
  • INFOBIP\_BASE\_URL: Your account-specific API domain. Obtain from Infobip portal dashboard. Format: String (e.g., xxxxx.api.infobip.com).
  • YOUR\_VERIFIED\_PHONE\_NUMBER: (Optional, for testing) The phone number linked to your Infobip trial account. Format: String (e.g., +15551234567).
  • PORT: (Optional, for server) The port number for the Express server to listen on. Format: Number.
  • Fallback Mechanisms: For simple SMS sending, implement basic fallback by retrying requests (see Error Handling below). For critical systems, consider alternative providers or channels.

5. Production-Ready Error Handling and Logging

Implement solid error handling for robust applications.

  • Error Handling Strategy:
  • Both sendManual.js and sendSdk.js include try...catch blocks.
  • Specific Infobip errors (usually returned in the response body on non-2xx status codes) are parsed and returned in a consistent { success: false, errorMessage: '...', errorDetails: '...', statusCode: ... } format.
  • Network errors or request setup issues are also caught.
  • The API layer (server.js) catches errors during request processing and returns appropriate HTTP status codes (400 for bad input, 500 for server errors, or the status code from Infobip if available).
  • Logging:
  • We are using basic console.log and console.error.
  • For production, replace these with a structured logging library like pino or winston. This enables:
  • Different log levels (debug, info, warn, error).
  • Outputting logs in JSON format for easier parsing by log management systems.
  • Writing logs to files or external services.
  • Conceptual Example (using Pino): Note: This requires installing pino (npm install pino) and initializing the logger.
    npm install pino pino-pretty
    const pino = require('pino');

    const logger = pino({
        level: process.env.LOG_LEVEL || 'info',

        transport: process.env.NODE_ENV !== 'production' ? { target: 'pino-pretty' } : undefined,
    });

     app.listen(port, () => {
        logger.info(`SMS API server listening on port ${port}`);
        logger.info(`Infobip Base URL configured: ${infobipConfig.domain}`);
     });
  • Retry Mechanisms:
  • Sending an SMS is often idempotent (sending the same message twice might be acceptable or undesirable depending on context).
  • For transient network errors or specific temporary Infobip issues (e.g., 5xx status codes), you might implement retries.
  • Use libraries like async-retry or implement a manual loop with exponential backoff (wait longer between each retry).
  • Caution: Be careful not to retry on permanent errors (like invalid API keys or invalid phone numbers - 4xx errors) or you'll waste resources.
  • Conceptual Example (using async-retry): Note: This requires installing async-retry (npm install async-retry) and assumes a logger instance is available.
    npm install async-retry
    const retry = require('async-retry');



         const sendOperation = async (bail, attemptNumber) => {

             const client = initializeInfobipClient(config);
             try {
                logger.info(`Attempt ${attemptNumber}: Sending SMS via SDK to ${destinationNumber}`);
                const infobipResponse = await client.channels.sms.send(sendSmsPayload);
                return infobipResponse;
             } catch (error) {

                if (error.response && error.response.status >= 400 && error.response.status < 500) {
                    logger.error(`Permanent error detected (Status ${error.response.status}). Bailing out.`, error);
                    bail(error);
                }

                throw error;
             }
         };


         const response = await retry(sendOperation, {
             retries: 3,
             factor: 2,
             minTimeout: 1000,
             maxTimeout: 5000,
             onRetry: (error, attemptNumber) => {
                 logger.warn({ err: error }, `Attempt ${attemptNumber} failed. Retrying...`);
             }
         });


         const responseData = response.data;

         if (!responseData || !responseData.messages || responseData.messages.length === 0) {
             return { success: true, data: responseData, warning: ""Successful response but no message details found."" };
         }
         const singleMessageResponse = responseData.messages[0];
         return {
             success: true,
             messageId: singleMessageResponse.messageId,
             status: singleMessageResponse.status.name,
             groupName: singleMessageResponse.status.groupName,
             description: singleMessageResponse.status.description,
             bulkId: responseData.bulkId
         };

    } catch (error) {

         logger.error({ err: error }, 'Error sending SMS with SDK after retries');

         let errorMessage = error.message;
         let errorDetails = null;
         let statusCode = error.response ? error.response.status : null;

         if (error.response && error.response.data && error.response.data.requestError && error.response.data.requestError.serviceException) {
             errorMessage = error.response.data.requestError.serviceException.text || 'Unknown Infobip SDK service exception';
             errorDetails = error.response.data;
         } else if (error.response && error.response.data) {
             errorMessage = `Infobip SDK Error (Status ${statusCode})`;
             errorDetails = error.response.data;
         }

         return {
             success: false,
             errorMessage: errorMessage,
             errorDetails: errorDetails,
             statusCode: statusCode
         };
    }

Simpler Alternative: Send the Same SMS With SMSRoute (No-KYC, Direct Routes)

If you want to replace legacy aggregator SDK boilerplate, multi-week compliance queues, and opaque carrier surcharges with a single HTTP request, SMSRoute delivers global SMS over direct Tier-1 carrier interconnects with instant API access and transparent per-country pricing.

curl -X POST https://api.sendsmsnokyc.com/messages \
  -H "x-api-key: $SMSROUTE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": ["+14155551234"],
    "channel": ["sms"],
    "body": "Your verification code is 482910"
  }'
  • Instant onboarding: No KYC paperwork or sales queues β€” grab an API key and fund with crypto (BTC/USDT) or card.
  • Direct Tier-1 routes: Verify real handset delivery, DLR latency, and Sender ID preservation before launch via SMSRoute Live Carrier Testing.
  • Transparent global pricing: Compare exact per-country termination rates on our live pricing page.

Ship Global SMS in One API Call

Skip legacy SDK sprawl and carrier bottlenecks. Send OTPs, alerts, and bulk campaigns across 190+ countries with SMSRoute.

Explore SMSRoute Developers β†’