Skip to content

Latest commit

Β 

History

46 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ClickSend Node.js SDK

npm version npm downloads License: MIT Types: TypeScript

Official Node.js / TypeScript client for the ClickSend API β€” send SMS, MMS, voice and email messages, run SMS and MMS campaigns, manage numbers, contacts and subaccounts, and pull delivery receipts and reporting through a single authenticated HTTPS client.

This library is generated from ClickSend's official OpenAPI v3 specification and is maintained by ClickSend. It covers every endpoint of the ClickSend REST API.

Features

  • Messaging β€” SMS, MMS, voice / text-to-speech, transactional email, email-to-SMS
  • Campaigns β€” SMS and MMS campaigns
  • Numbers & sender IDs β€” dedicated numbers, own numbers, alpha tags, default senders
  • Contacts β€” contact lists, contacts and the address book
  • Account & billing β€” account details, transactions, subaccounts, referrals, reseller accounts
  • Delivery & reporting β€” delivery receipts, inbound messages, statistics
  • Extras β€” URL shortening, file uploads, number verification, international messaging
  • First-class TypeScript β€” every method takes a single, fully-typed request-parameters object; typed models for every request and response, .d.ts shipped in the package
  • Built on axios β€” bring your own AxiosInstance for interceptors, proxies, retries, or custom transports
  • HTTP Basic auth with your ClickSend username and API key
  • Identifiable traffic β€” requests are sent with a ClickSend-SDK/<version>/nodejs User-Agent by default
  • MIT licensed

Requirements

  • Node.js 14 or newer

Installation

npm install clicksend

Authentication

Every API class authenticates with HTTP Basic auth using your ClickSend username and API key, both available from the ClickSend Dashboard. Supply them through environment variables rather than hard-coding them:

export CLICKSEND_USERNAME="your-username"
export CLICKSEND_API_KEY="your-api-key"

Quickstart

Every API class takes a Configuration instance holding your credentials. Every method takes a single request-parameters object β€” there's no positional contentType argument to remember or skip.

Field names inside request/response bodies are snake_case (e.g. media_file, email_address_id, list_id), matching the API's wire format exactly β€” they are not camelCased. Only the outer request-parameters object's own keys (the method's named arguments, like sendSmsRequest or listId) are camelCase. Check the TypeScript types (or the API reference) for the exact field name rather than guessing.

import { Configuration, SmsApi } from 'clicksend';

const configuration = new Configuration({
  username: process.env.CLICKSEND_USERNAME,
  password: process.env.CLICKSEND_API_KEY,
});

const smsApi = new SmsApi(configuration);

const { data } = await smsApi.sendSms({
  sendSmsRequest: {
    messages: [
      {
        source: 'sdk',
        body: 'Hello from ClickSend!',
        to: '+61411111111',
      },
    ],
  },
});

console.log(data);

More Examples

View account details

import { Configuration, ManagementApi } from 'clicksend';

const configuration = new Configuration({
  username: process.env.CLICKSEND_USERNAME,
  password: process.env.CLICKSEND_API_KEY,
});

const managementApi = new ManagementApi(configuration);

const { data } = await managementApi.viewAccountDetails();
console.log(data);

Send an MMS

import { Configuration, MmsApi } from 'clicksend';

const configuration = new Configuration({
  username: process.env.CLICKSEND_USERNAME,
  password: process.env.CLICKSEND_API_KEY,
});

const mmsApi = new MmsApi(configuration);

const { data } = await mmsApi.sendMms({
  sendMmsRequest: {
    media_file: 'https://clicksend.com/logo.png',
    messages: [
      {
        to: '+61411111111',
        from: 'sdk',
        subject: 'Hello',
        body: 'Hello from ClickSend!',
        source: 'sdk',
      },
    ],
  },
});

console.log(data);

Configuration

import axios from 'axios';
import { Configuration, SmsApi } from 'clicksend';

const configuration = new Configuration({
  username: process.env.CLICKSEND_USERNAME,
  password: process.env.CLICKSEND_API_KEY,
  // Override the API base URL (default: https://rest.clicksend.com).
  basePath: 'https://rest.clicksend.com',
  // Headers sent on every request from this client.
  baseOptions: { headers: { 'X-My-Header': 'value' } },
});

// Bring your own axios instance for interceptors, proxies, retries, etc.
const axiosInstance = axios.create();
axiosInstance.interceptors.request.use((config) => {
  console.log(config.method, config.url);
  return config;
});

const smsApi = new SmsApi(configuration, undefined, axiosInstance);

Each API method also accepts a final options argument (an AxiosRequestConfig) for per-call overrides, e.g. { headers: { ... } }.

Error Handling

Every method returns a promise that resolves to an AxiosResponse (.data, .status, .headers) and rejects with an AxiosError on non-2xx responses:

try {
  const { data } = await smsApi.sendSms({ sendSmsRequest: { messages: [/* ... */] } });
  console.log(data);
} catch (err) {
  if (axios.isAxiosError(err)) {
    console.error(err.response?.status, err.response?.data); // HTTP status + parsed error payload
  } else {
    throw err;
  }
}

Documentation

Versioning

This package follows semantic versioning. Breaking changes are released as major versions.

Support

License

Released under the MIT License.


Keywords: clicksend, sms, sms api, send sms, bulk sms, text message, texting, mms, mms api, voice, voice call, text to speech, tts, ivr, email to sms, sms campaign, mms campaign, url shortening, number verification, messaging, notifications, otp, 2fa, two factor authentication, transactional sms, marketing sms, appointment reminders, alerts, nodejs, node, typescript, rest api, clicksend sdk

About

Repo for a new and improved nodejs SDKs

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages