Developer Guide: Node.js Express Bulk SMS with Infobip - code-examples -

Frequently Asked Questions

Use the Infobip API and Node.js SDK along with Express.js to create an API endpoint that accepts recipient phone numbers and a message, sending it as a bulk SMS broadcast via Infobip's platform. This setup handles the backend logic for sending notifications, alerts, and other mass communications.
The Infobip API and its official Node.js SDK enable efficient sending of SMS messages, WhatsApp messages, and other communications. It integrates smoothly with a Node.js and Express server, streamlining the messaging logic.
Express.js simplifies building a RESTful API endpoint to handle incoming broadcast requests. Its minimal design and widespread adoption make it an ideal framework for managing requests and responses in Node.js SMS applications.
Obtain your API key and base URL from the Infobip dashboard. For local development, store these in a .env file and load them using dotenv. Never commit the .env file. In production, use platform-specific environment variable settings.
Install express, @infobip-api/sdk, and dotenv for core functionality. Nodemon is recommended for development to restart the server automatically on code changes. Optionally, use Prisma and SQLite for a database, and express-rate-limit for rate limiting.
Create folders for routes, controllers, services, and config. Implement controllers to manage requests, services to handle Infobip interactions, and routers to define endpoints. Centralize Infobip configuration, error handling, and API initialization logic in separate files.
The /api/broadcast endpoint accepts POST requests containing an array of recipient phone numbers and the message text. The controller then utilizes the Infobip Service to send the message to all provided numbers via SMS using the Infobip API.
Implement validation in the controller to catch invalid input. The Infobip Service should handle API errors and provide specific messages for detailed logging. Use a global error handler in Express for unhandled errors and avoid leaking sensitive data in production.
Use the express-rate-limit middleware in your Express app to protect the /api/broadcast endpoint from excessive requests. Configure the limits based on your Infobip account limits and expected traffic patterns. Return informative error messages to clients exceeding the rate limit.
Add a GET route, typically at /health, that returns a 200 OK status with a JSON payload like { status: 'UP' }. This allows monitoring systems to quickly check the server's availability. You can also include a timestamp.
Log essential data (e.g., bulkId) for monitoring. Consider using dedicated logging libraries like Winston or Pino for structured logging, log levels, and various output options (files, external services). Avoid logging sensitive details like the full API response body or API key.
Prisma and a database like SQLite (or others like Postgres) offer a persistent record of each broadcast request, including recipient details, message content, timestamps, and Infobip response data (bulkId, individual message statuses). This is essential for auditing and tracking message deliveries.
Use libraries like async-retry or p-retry with exponential backoff and jitter for transient errors like 429 (Too Many Requests). Be cautious with retries for actions like SMS sending; consider idempotency or rely on Infobip's delivery reports for status updates instead of client-side retries.
Test with invalid input, bad phone numbers, or a temporarily wrong API key to see error handling. If possible, use tools like Postman to simulate network issues or trigger Infobip-specific errors to evaluate the robustness of your error logging and response handling.
Customize the "from" parameter in the Infobip API request when you want to display an alphanumeric sender ID (your brand name) instead of a phone number. Check Infobip's regulations for your country, as these IDs are subject to specific restrictions and require prior approval in many regions.