Sending SMS with Nodejs using Sendchamp SMS API

A quick walk-through on how to seamlessly implement Sendchamp SMS API with Nodejs

Aliyu Abubakar

Aug 1, 2021

Learn how to quickly send SMS messages with Node.js using sendchamp API. In this guide we will walk you through:

  1. Signing up free Sendchamp account
  2. Create a Sender ID
  3. Setting up a Nodejs Application
  4. Sending your first message

Prerequisite

Before you can get started, you need the following already set up:

  • Node.js and a familiarity with how to create a new app.
  • A sendchamp account

Signing up free sendchamp account

If you Already have an account? skip to the next section You can sign up for a free sendchamp account here.

image

When you sign up, you'll have to verify your email address. This allows sendchamp to verify your identity.

After you've verified your email address, you'll be asked a question in order to get you started in a way that's relevant to you.

After you finish setting up your account, you'll have access to your dashboard where you can access your API Key and perform dashboard communication functions.

Create a Sender ID

Once your account is created, you’ll need to add a new sender ID in order to send SMS Messages. Click channels on your dashboard under settings, click on SMS channel and add a sender ID. Take note of your ID, because you'll use it later.

image

Setting up a Nodejs Application

Create a new node app with NPM.

npm init 

Create a new file named index.js in the project and paste the provided "Send SMS" code into the file.

Code Sample

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api.sendchamp.com/api/v1/sms/send',
  'headers': {
    'Accept': 'application/json',
    'Authorization': 'Bearer ACCESS_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({"to":["2348055372961"],"message":"Hello from Olumide Latest","sender_name":"Kuda", "route":"non_dnd"})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
}); 

Parameters

ParameterYour Value
Route.Here you can specify a route you want your SMS to go through.
to required.This represents the destination phone number. The phone number(s) must be in the international format (Example: 23490126727). You can also send to multiple numbers. To do that put numbers in an array (Example: [ '234somenumber', '234anothenumber' ]).
message required.Text message being sent.
sender_name required.Represents the sender of the message. This Sender ID must have been requested via the dashboard or use "Sendchamp" as default

Sending your SMS message

Now you can execute the code and send your test SMS message. Run the following command:

node index.js 

The code you used in the index.js file sends a POST request to the sendchamp API endpoint to send the SMS message.

Thanks for getting to the end of the tutorial. Be sure that if you have more questions, you can join our [Slack community] (https://bit.ly/community-tutorial-link) here and we will help resolve it.

© 2022 Sendchamp. All rights reserved.