SDK
v0.1.0
Node.js SDK
The official JavaScript / TypeScript SDK for Sendexa. One package, one client, every API — SMS, OTP, WhatsApp, Email, Voice, and Webhook verification.
Zero Dependencies
Built on the native fetch API — no extra packages, no version conflicts, smaller bundle.
Edge Compatible
Works in Node.js 18+, Cloudflare Workers, Vercel Edge Functions, and Deno.
Fully Typed
Complete TypeScript types for every request body, response, and error — no any.
Ships ESM + CJS
Dual-format output — works with import, require, and all modern bundlers.
Installation
Bash
npm install sendexa/sdk
Requirements
Node.js 18 or later. The SDK uses the native
fetch and crypto.subtle APIs — no polyfills needed in Node 18+, Cloudflare Workers, or Vercel Edge.Initialise the Client
Create one client instance per application and reuse it — it is stateless and safe to share across requests.
TypeScript
import { Sendexa } from 'sendexa/sdk';const client = new Sendexa({apiKey: process.env.SENDEXA_API_KEY!,apiSecret: process.env.SENDEXA_API_SECRET!,});
API Examples
Send single and bulk SMS messages with delivery tracking.
TypeScript
// Send a single SMSconst { data } = await client.sms.send({to: '0244123456',from: 'MyBrand',message: 'Your order #1234 has been confirmed!',});console.log(data.messageId, data.status);// Send bulk SMS (up to 10 000 recipients)await client.sms.sendBulk({from: 'MyBrand',message: 'Hello from MyBrand!',messages: [{ to: '0244123456', message: 'Hi Alice!' },{ to: '0555987654' }, // uses shared message],});// Check delivery statusconst { data: status } = await client.sms.getStatus(data.messageId);console.log(status.status); // 'delivered'// Resend a failed messageawait client.sms.resend(data.messageId);
Error Handling
All API errors throw a SendexaError with structured fields for easy branching.
TypeScript
import { Sendexa, SendexaError } from 'sendexa';try {await client.sms.send({ to: '0244123456', from: 'MyBrand', message: 'Hi!' });} catch (err) {if (err instanceof SendexaError) {console.error(err.status); // HTTP status e.g. 403console.error(err.code); // API code e.g. "SENDER_ID_NOT_APPROVED"console.error(err.message); // Human text e.g. "Sender ID not approved"console.error(err.requestId);// Trace ID for Sendexa support}}
| Property | Type | Description |
|---|---|---|
| status | number | HTTP status code (400, 401, 403, 429…) |
| code | string | Machine-readable error code from the API |
| message | string | Human-readable description of the error |
| requestId | string? | Sendexa trace ID — include when contacting support |
| raw | unknown | The full raw error payload from the API |
Best Practices
- Create one
Sendexainstance at startup and reuse it — do not instantiate per request - Store credentials in environment variables, never in source code
- Always
await client.webhooks.verify()before processing any webhook event - Catch
SendexaErrorseparately from generic errors so you can branch onerr.code - Set a custom
timeoutif your environment has strict request limits (default: 30 s)