Created
October 28, 2017 12:38
-
-
Save BadgerCode/984dbacd6ecd1cb39aced8f07908da56 to your computer and use it in GitHub Desktop.
Sends a SMS message using Esendex's REST API and Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); // npm install request | |
var username = "user@domain.com"; | |
var password = "password"; // Sorry no API keys! | |
var accountReference = "EX0123456"; // https://www.esendex.com/echo (on the right hand side EX12345) | |
var recipient = "447123456789"; // Your number | |
var message = "Hello world!"; | |
request( | |
{ | |
url: 'http://api.esendex.com/v1.0/messagedispatcher', | |
method: 'POST', | |
auth: { | |
user: username, | |
pass: password | |
}, | |
json: {'accountreference': accountReference, 'messages': [ { "to": recipient, "body": message } ]} | |
}, | |
function(error, response, body){ | |
if(!error && response.statusCode == 200){ | |
console.log("Success!"); | |
} | |
else { | |
console.log("Something went wrong"); | |
console.log("Error: ", error); | |
console.log("Status: ", response.statusCode); | |
console.log("Body: ", body); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment