DEV Community

Aliyu Abubakar
Aliyu Abubakar

Posted on

2 2

Sending SMS with nodejs using sendchamp SMS API

The Sendchamp SMS API allows you to send SMS anywhere around the world. With your verified Sender ID, you can use the SMS API to facilitate outbound messages.

In this article, you will learn how to send SMS messages with Node.js.

Prerequisite

Before you can get started, make sure you have:

  • JavaScript knowledge and familiarity with nodejs.
  • Nodejs installed on your machine
  • Sendchamp account

To get started with Sendchamp SMS API, sign up on Sendchamp to get your API credentials. Once you signed up, go to your Sendchamp Dashboard to get your API key in the account settings section and you will find APIs & Webhook.

Setting up your Nodejs Application

Create a .js file, let’s call it index.js, and in the file, initialize an instance with your credentials:

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'
  },

Enter fullscreen mode Exit fullscreen mode

Make sure to replace ACCESS_KEY with your correct public access key on your sendchamp dashboard.

Sending SMS Messages

To send a message, pass the Sender ID you are sending the message from, a recipient number, message to be sent and the route.

Let’s try to hard-code a phone number (which should start with a country code, e.g. “2349039099438”) and a message to test out the SMS API:

body: JSON.stringify({"to":["2349039099438"],"message":"Testing Sendchamp SMS API","sender_name":"Sendchamp", "route":"dnd"})
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
Enter fullscreen mode Exit fullscreen mode

Let’s see if we will get an SMS.

Image description

Leave a comment if you need further clarifications. You can join our developer community here

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay