Frequently Asked Questions
Use the Vonage Messages API with the @vonage/server-sdk. Set up an Express route that takes the recipient's number, image URL, and an optional caption, then use vonage.messages.send() to send the MMS message.
The Vonage Messages API is a unified platform that lets you send various types of messages like SMS, MMS, WhatsApp, and more through a single API. It simplifies communication across multiple channels.
MMS functionality through long codes and toll-free numbers is largely a US/Canada-centric feature due to carrier and market dynamics in those regions. SMS, however, offers much broader global reach through the Vonage API.
Using the Vonage Server SDK simplifies the process of sending MMS messages, which is primarily supported in the US market, and text SMS messages, allowing you to add robust messaging features to your applications seamlessly. Use it whenever you want to integrate Vonage APIs into your Node.js projects.
MMS sending with long codes/toll-free numbers via Vonage is primarily for US/Canada. Consult the Vonage documentation for the latest information on international MMS support and any applicable restrictions or alternative solutions.
Create a Node.js project, install Express, the Vonage Server SDK, and dotenv. Configure your Vonage account and application, then set up API routes in your server to handle sending requests and webhooks. Ensure secure storage of your API credentials.
ngrok creates a public URL that tunnels to your local server, enabling Vonage to send webhooks (delivery receipts) to your application during development. This is mainly for testing purposes while not in a deployed environment.
Dotenv loads environment variables from a .env file, keeping your sensitive Vonage API keys and secrets out of your codebase. This is essential for security and best practice.
Set up a webhook endpoint (e.g. /webhooks/status) in your Express app. Configure this URL in your Vonage application settings. Vonage will send POST requests to this endpoint with message status updates. Ensure you respond with a 200 OK status.
The private.key file is essential for authenticating your application with the Vonage Messages API. It works in conjunction with your Application ID, ensuring secure communication. Store this file securely and never commit it to version control.
Open your terminal and use npm: 'npm install @vonage/server-sdk'. This will install the necessary library for interacting with the Vonage API.
Use the E.164 format for phone numbers, such as +14155552671. Ensure the plus sign and country code are included.
Implement robust input validation, use authentication/authorization middleware, set up rate limiting, and secure your webhook endpoint. Never expose your API keys or private key in your codebase.
Send MMS with Vonage Messages API, Node.js & Express
Build a Node.js Express API that sends MMS and SMS messages through Vonage Messages API. This guide covers project setup, authentication with JWT-based credentials, webhook handling for delivery receipts, error management, and production deployment strategies.
Create a functional Express server with two endpoints:
/send-mms
for multimedia messages with images and/send-sms
for text messages. You'll learn to handle Vonage's authentication, implement webhook security, manage errors, and deploy a production-ready messaging service.Project Overview and Goals
Goal: Create a Node.js Express API that programmatically sends MMS messages (with images) and SMS messages using Vonage Messages API.
Problem Solved: Build a backend messaging service that enables applications to send rich media notifications without managing carrier complexities directly. Send MMS where supported (US/Canada) and fall back to SMS for other regions.
What You'll Build:
/send-mms
and/send-sms
endpointsCritical MMS Limitations (October 2025):
⚠️ Geographic Restrictions:
⚠️ Technical Constraints:
⚠️ Carrier Compatibility:
Regulatory Requirements:
For international messaging or broader channel support, consider Vonage's WhatsApp or Viber channels via the same Messages API.
Technologies Used:
@vonage/server-sdk
(v3.12+): Official Vonage Server SDK for Node.js. As of October 2025, version 3.x is current with modern ES module support and improved TypeScript definitions.dotenv
(v16.0+): Module to load environment variables from a.env
file, keeping sensitive credentials secure.Important Version Notes:
npm list @vonage/server-sdk
andnode --version
System Architecture:
Your messaging system follows this request flow:
/send-mms
or/send-sms
vonage.messages.send()
method contacts Vonage Messages APIWebhook Flow (Optional):
/webhooks/status
endpointExpected Outcome:
After completing this guide, you'll have:
✅ Running Express server listening on port 3000 (configurable)
✅
POST /send-mms
endpoint accepting recipient, image URL, and caption✅
POST /send-sms
endpoint accepting recipient and text message✅ Secure credential storage using environment variables
✅ Basic error handling with detailed logging
✅ (Optional) Webhook endpoint for delivery receipt tracking
Success Criteria:
Prerequisites:
node --version
. Download Node.js1. Setting up the Project
Initialize your Node.js project and install the necessary dependencies.
1.1 Create Project Directory
Open your terminal and create a new directory:
1.2 Initialize Node.js Project
Create
package.json
to manage dependencies:This generates a default
package.json
with project metadata.1.3 Install Dependencies
Install Express (web framework), Vonage SDK (API client), and dotenv (environment variables):
Package purposes:
.env
file, keeping sensitive credentials secure.1.4 Create Project Files
Create core application files:
1.5 Configure .gitignore
Prevent sensitive files from entering version control. Add these lines to
.gitignore
:Security note: Never commit
.env
orprivate.key
files. These contain credentials that authenticate your Vonage account.Project Structure:
Your project contains these files:
index.js
package.json
package-lock.json
.env
.gitignore
node_modules/
private.key
Key principle: Keep credentials in
.env
and.gitignore
to prevent accidental exposure.2. Vonage Account and Application Setup
Configure your Vonage account and create a Vonage Application for Messages API authentication. The Messages API uses JWT authentication with public/private key pairs.
Dashboard Navigation Note: As of October 2025, Vonage's dashboard layout may differ slightly. Look for "Communications APIs" or "Messages API" sections if menu items have moved.
Step 1: Access Dashboard and Locate Credentials
Step 2: Complete 10DLC Registration (US Long Codes Only)
Required for US Application-to-Person (A2P) messaging:
Toll-free alternative: Skip 10DLC by using toll-free numbers (1-8XX format). Requires separate verification via Vonage Support (3-5 business days).
Important: Unregistered long codes experience filtered messages, reduced throughput (1 msg/sec vs 60+), and potential number suspension.
Step 3: Purchase US/Canada Number
+12015550123
)Step 4: Create Vonage Application
private.key
file to your computerhttps://example.com/webhooks/inbound
(placeholder for now)https://example.com/webhooks/status
(delivery receipts)xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
)Step 5: Link Number to Application
Step 6: Set Default SMS API (Recommended)
This ensures Vonage SDK uses the modern Messages API by default.
Credentials Summary:
Store these values – you'll use them in
.env
configuration:+12015550123
)private.key
file3. Environment Configuration
Store credentials securely using environment variables in a
.env
file.Step 1: Move Private Key to Project (Optional but Recommended)
Move the downloaded
private.key
file to your project root directory:This file is already listed in
.gitignore
to prevent accidental commits.Step 2: Configure .env File
Open
.env
and add these variables with your actual credentials:Variable Explanations:
VONAGE_API_KEY
VONAGE_API_SECRET
VONAGE_APPLICATION_ID
VONAGE_PRIVATE_KEY_PATH
VONAGE_NUMBER
APP_PORT
MY_SECRET_API_KEY
Security Requirements:
⚠️ Never commit
.env
to Git – it contains authentication credentials⚠️ Never commit
private.key
to Git – it authenticates all API requests⚠️ Use strong secrets – generate with
openssl rand -hex 32
for production⚠️ Restrict file permissions – run
chmod 600 private.key
on Unix systems⚠️ Production deployment – use platform environment variables (Heroku, AWS, Vercel) instead of
.env
filesE.164 Format Requirement:
Phone numbers must use E.164 international format:
+[country code][number]
+12015550123
(country code 1, area code 201, number 5550123)+14165550123
(country code 1, area code 416, number 5550123)4. Implement Express Server
Set up the basic Express server structure.
Edit your
index.js
file:Explanation:
require('dotenv').config();
: Loads variables from the.env
file intoprocess.env
.express()
: Creates an Express application instance.app.use(express.json())
,app.use(express.urlencoded(...))
: Middleware to parse incoming JSON and URL-encoded request payloads, making them available asreq.body
.app.get('/')
: A simple route to confirm the server is running.app.listen()
: Starts the server and makes it listen for connections on the specified port.You can run this basic server now:
You should see the ""Server listening..."" message in your console. Open
http://localhost:3000
in your browser to see the welcome message. PressCtrl+C
to stop the server.5. Implement Sending Logic (MMS & SMS)
Now, let's integrate the Vonage SDK and create the API endpoints for sending messages.
First, initialize the Vonage client near the top of
index.js
, after loading dotenv:Now, add the API endpoints below the basic
/
route and before theapp.listen
call:MMS Image Requirements and Best Practices (October 2025):
Supported Image Formats:
Size and Dimension Limits:
Image URL Requirements:
Caption Guidelines:
Common MMS Failures and Solutions:
Explanation:
vonage
instance is initialized using credentials from.env
. A check is added to ensure the private key file exists. Error handling is included for initialization failure.async
functions to allow usingawait
for the asynchronousvonage.messages.send
call.to
,imageUrl
/text
) are present in the request body (req.body
). Production applications need more robust validation (e.g., using libraries likejoi
orexpress-validator
).vonage.messages.send()
: This is the core function from the Vonage SDK used to send messages via the Messages API.message_type
: Set to"image"
for MMS or"text"
for SMS.image
: An object containing theurl
(must be publicly accessible) and an optionalcaption
for MMS. Supported image types are typically JPEG, PNG, GIF. Check Vonage documentation for specifics and size limits.text
: The message content for SMS.to
: The recipient's phone number in E.164 format (e.g.,+14155550101
).from
: Your Vonage virtual number (VONAGE_NUMBER
).channel
: Explicitly set to"mms"
or"sms"
.message_uuid
provided by Vonage. On failure, it logs the error and returns an appropriate status code (400 for bad input, 500 or Vonage's error status for sending issues) with an error message.try...catch
block handles errors during the API call. It attempts to log detailed error information from Vonage (error.response.data
) if available.6. Handling Webhooks (Optional - Delivery Receipts)
To confirm message delivery status, Vonage sends information to the ""Status URL"" you configured in your Vonage Application. Let's set up ngrok and a basic webhook handler.
Start ngrok: If you haven't already, download and set up ngrok. Run it to expose your local server's port (e.g., 3000).
ngrok will provide a forwarding URL (e.g.,
https://abcd-1234.ngrok.io
). Copy thehttps
version.Update Vonage Application Status URL:
/webhooks/status
. Example:https://abcd-1234.ngrok.io/webhooks/status
.POST
.Add Webhook Endpoint in
index.js
: Add this route handler before theapp.listen
call:Explanation:
POST
requests at the path you configured in Vonage (/webhooks/status
).message_uuid
,status
(delivered
,failed
,rejected
, etc.),timestamp
, and potentially error codes. Refer to the Vonage Messages API documentation for the exact payload structure.200 OK
status immediately. If Vonage doesn't receive a 200 OK, it will retry sending the webhook, leading to duplicate processing.Restart your server (
node index.js
) after adding the webhook. Now, when you send messages, status updates should be logged to your console via ngrok.7. Security Considerations
While this guide focuses on basic functionality, production applications require stronger security:
to
number format,imageUrl
validity and source,text
length and content). Libraries likejoi
orexpress-validator
are recommended.express-rate-limit
.private.key
file has restricted permissions on the server. Consider loading the key content directly into an environment variable instead of relying on a file path in production.8. Error Handling and Logging
Robust error handling and logging are vital for debugging and monitoring.
{ success: false, error: ""Error message"", code: ""ERROR_CODE"" }
).Winston
for production instead ofconsole.log
. Configure log levels (info, warn, error) and output destinations (file, console, external service).error.response.data
object.async-retry
) with exponential backoff for sending requests. Be cautious not to retry indefinitely or for non-recoverable errors.9. Testing and Verification
Test your endpoints thoroughly.
Start Your Server:
Send Test MMS (using cURL): Replace placeholders with your test recipient number (must be whitelisted if your Vonage account is in trial mode) and a valid public image URL.
(Note: Add the
-H ""x-api-key: ...""
header if you implemented the example security middleware from Section 7)Expected Success Response:
Check the recipient's phone for the MMS message. Check your console logs for success messages.
Send Test SMS (using cURL):
(Note: Add the
-H ""x-api-key: ...""
header if you implemented the example security middleware from Section 7)Expected Success Response:
Check the recipient's phone for the SMS message. Check your console logs.
Test Error Cases:
to
,imageUrl
,text
)..env
with incorrect Vonage credentials to trigger authentication errors.Verify Webhooks (if configured):
node index.js
is running for ""Status Webhook Received"" logs after sending messages.http://127.0.0.1:4040
).10. Troubleshooting and Caveats
MMS Geographic and Technical Limitations:
Trial Account Limitations:
Common Error Codes (Vonage Messages API - October 2025):
invalid-params
unauthorized
unsupported-channel
media-invalid
media-too-large
throttled
insufficient-balance
spam-detected
Debugging Steps:
Check Vonage Dashboard Logs:
Verify Number Capabilities:
Test Image URL Accessibility:
Check 10DLC Status (US Long Codes):
Validate E.164 Format:
Enable SDK Debug Logging:
Production Deployment Checklist: