Sidebar Menu

SMS Notify! API
Quick Start: JavaScript

There are three steps to integrating our programmable SMS API into your Node.js project.

1. Create an account.

Sign up for an Esendex account. When you register you will receive a license key. You will need this to use the API.

2. Install Node.js.

Install Node.js if it is not on your computer already. To check, run this command in your terminal: node -v

PS C:\> node -v
v18.16.0

3. Send a test message.

Create a new JavaScript module file. Let's call it demo.mjs.

You can use the SendMessage method to send a text message. Add the displayed code to your new file.

Replace the LicenseKey value with your account's license key.

Replace the To value with your own mobile phone number.

const url = 'https://messaging.esendex.us/Messaging.svc/SendMessage';
const response = await fetch(url, {
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        'Body': 'Hi, this message was sent using JavaScript.',
        'LicenseKey': '00000000-0000-0000-0000-000000000000',
        'To': ['7575559999'],
        'UseMMS': false
    }),
    method: 'POST'
});
const messages = await response.json();
const message = messages[0];

console.log(`Message status: ${message['MessageStatus']}`);

Run the project in your terminal with this command: node demo.mjs. If the message status is 201 (the code for Ready), your call to the API was a success! You will receive the text message shortly on your phone.

PS C:\JsDemo> node demo.mjs
Message status: 201