Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
The SMSGlobal Node library provides convenient access to the SMSGlobal REST API from node applications.
Sign up for a free SMSGlobal account today and get your API Key from our advanced SMS platform, MXT. Plus, enjoy unlimited free developer sandbox testing to try out your API in full!
Check out the code examples
Rest API credentials can be provided in the SMSGlobal client or node environment variables. The credential variables are SMSGLOBAL_API_KEY
and SMSGLOBAL_API_SECRET
npm install --save smsglobal
smsglobal
in your fileconst apiKey = 'YOUR_API_KEY';
const apiSecret = 'YOUR_API_SECRET';
var smsglobal = require('smsglobal')(apiKey, secret);
All method return promise if no callback is given
var payload = {
origin: 'from number',
destination: 'destination',
message: 'This is a test message'
}
smsglobal.sms.send(payload, function (error, response) {
console.log(response);
});
var promise = smsglobal.sms.getAll();
promise
.then(function(response) {
console.log(response)
})
.catch(function(error){
console.log(error)
});
var id = 'outgoing-sms-id';
var promise = smsglobal.sms.get(id);
promise
.then(function(response) {
console.log(response)
})
.catch(function(error){
console.log(error)
});
var promise = smsglobal.sms.incoming.getAll();
promise
.then(function(response) {
console.log(response)
})
.catch(function(error){
console.log(error)
});
var id = 'incoming-sms-id';
var promise = smsglobal.sms.incoming.get(id);
promise
.then(function(response) {
console.log(response)
})
.catch(function(error){
console.log(error)
});
var payload = {
origin: 'from number',
message: '{*code*} is your SMSGlobal verification code.',
destination: 'destination'
};
// {*code*} placeholder is mandatory and will be replaced by an auto generated numeric code.
smsglobal.otp.send(payload, function(error, response) {
if (response) {
console.log(response);
}
if (error) {
console.log(error);
}
});
Success response object
{
statusCode: 200,
status: 'OK',
data: {
requestId: '404372541683676561917558',
destination: '61400000000',
validUnitlTimestamp: '2020-11-18 17:08:14',
createdTimestamp: '2020-11-18 16:58:14',
lastEventTimestamp: '2020-11-18 16:58:14',
status: 'Sent'
}
}
Error response object in the case of validation error
{
statusCode: 400,
status: 'Bad Request',
data: {
errors: {
message: {
errors: [
'Message template should contain a placeholder for code i.e. {*code*}.'
]
}
}
}
}
The OTP request can be cancelled if it's not expired and verified yet. It can be done by either using requestId
or destination number
. The followings are examples of each method:
var id = 'otp-request-id'; // requestId received upon sending an OTP
var promise = smsglobal.otp.cancelByRequestId(id)
promise.then((response) => {
console.log(response)
}).catch((err) => {
console.log(error)
});
var destination = 'destination-number';
var promise = smsglobal.otp.cancelByDestination(id)
promise.then((response) => {
console.log(response)
}).catch((err) => {
console.log(error)
});
Success response object
{
statusCode: 200,
status: 'OK',
data: {
requestId: '404372541683676561917558',
destination: '61400000000',
validUnitlTimestamp: '2020-11-18 17:08:14',
createdTimestamp: '2020-11-18 16:58:14',
lastEventTimestamp: '2020-11-18 16:58:14',
status: 'Cancelled'
}
}
The OTP code entered by your user can be verified by either using requestId
or destination number
. The followings are examples of each method:
var id = 'otp-request-id'; // requestId received upon sending an OTP
var code = 'otp-code'; // input code entered by your user
smsglobal.otp.verifyByRequestId(id, code, function(error, response) {
if (response) {
console.log(response);
}
if (error) {
console.log(error);
}
});
var destination = 'destination-number';
var code = 'otp-code'; // input code entered by your user
smsglobal.otp.verifyByDestination(id, code, function(error, response) {
if (response) {
console.log(response);
}
if (error) {
console.log(error);
}
});
Success response object
{
statusCode: 200,
status: 'OK',
data: {
requestId: '404372541683676561917558',
destination: '61400000000',
validUnitlTimestamp: '2020-11-18 17:08:14',
createdTimestamp: '2020-11-18 16:58:14',
lastEventTimestamp: '2020-11-18 16:58:14',
status: 'Verified'
}
}
Run the tests:
npm test
To run test with code coverage report
npm run mocha-only
For any query contact us
FAQs
SDK for SMSGlobal rest api
The npm package smsglobal receives a total of 558 weekly downloads. As such, smsglobal popularity was classified as not popular.
We found that smsglobal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.