eSMSAfrica
Pricing Login Get started
Node.js

How to send SMS from Node.js

Send your first SMS from a Node.js app with a single HTTPS request to the eSMS Africa SMS API. No SDK required - just fetch.

javascript
const res = await fetch("https://api.esmsafrica.io/v1/sms/send", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.ESMS_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    to: "+254712345678",
    from: "MyBrand",       // your registered sender ID
    message: "Hello from Node.js",
  }),
});

const data = await res.json();
console.log(data); // { id, status, ... }

1. Get your API key

Create a free account and copy your API key from the dashboard. Keep it server-side - never ship it in front-end code.

2. Send an SMS

Use the built-in fetch (Node 18+). Recipients must be in international format (e.g. +254... for Kenya).

javascript
const res = await fetch("https://api.esmsafrica.io/v1/sms/send", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.ESMS_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    to: "+254712345678",
    from: "MyBrand",       // your registered sender ID
    message: "Hello from Node.js",
  }),
});

const data = await res.json();
console.log(data); // { id, status, ... }

3. Handle the response

A 2xx response means the message was accepted. Store the returned message id so you can match it to a delivery report later.

javascript
if (!res.ok) {
  throw new Error(`SMS failed: ${res.status} ${JSON.stringify(data)}`);
}
// data.id -> keep this to reconcile the DLR webhook

FAQ

Do I need an SDK to send SMS from Node.js?

No. The API is a plain HTTPS endpoint, so Node 18+ fetch (or axios) is enough. An official Node SDK is also available if you prefer.

What number format should I use?

International E.164 format, e.g. +254712345678 for Kenya. The API delivers to every African network.

Ready to send?
Get an API key free and reach every African network.