Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [9.x, 10.x, 12.x, 14.x]
node-version: [22.x, 24.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -31,4 +31,4 @@ jobs:
file: ./ccoverage.lcov
flags: unittests
name: codecov-umbrella
fail_ci_if_err: true
fail_ci_if_error: true
114 changes: 54 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
# SMSGlobal node SDK


![Build](https://github.com/smsglobal/smsglobal-node/workflows/Build/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/smsglobal/smsglobal-node/branch/master/graph/badge.svg)](https://codecov.io/gh/smsglobal/smsglobal-node)
[![Node](https://img.shields.io/node/v/smsglobal)](https://www.npmjs.com/package/smsglobal)
[![npm](https://img.shields.io/npm/v/smsglobal)](https://www.npmjs.com/package/smsglobal)
[![Downloads](https://img.shields.io/npm/dm/smsglobal.svg)](https://www.npmjs.com/package/smsglobal)


The SMSGlobal Node library provides convenient access to the SMSGlobal REST API from node applications.

Sign up for a [free SMSGlobal account](https://www.smsglobal.com/mxt-sign-up/?utm_source=dev&utm_medium=github&utm_campaign=node_sdk) 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!


## Example
Check out the [code examples](examples)
Check out the [code examples](examples)


## SMSGlobal rest API credentials
## SMSGlobal REST API credentials

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`


## Installation

```
npm install --save smsglobal
```


## Usage

* Require `smsglobal` in your file
Expand All @@ -39,9 +33,9 @@ const apiSecret = 'YOUR_API_SECRET';
var smsglobal = require('smsglobal')(apiKey, secret);
```

> All method return promise if no callback is given
> All methods return a promise if no callback is given.

### To send a sms
### To send an SMS
```js
var payload = {
origin: 'from number',
Expand All @@ -53,7 +47,7 @@ smsglobal.sms.send(payload, function (error, response) {
console.log(response);
});
```
### To fetch a list outgoing sms
### To fetch a list of outgoing SMS

```js
var promise = smsglobal.sms.getAll();
Expand All @@ -67,7 +61,7 @@ promise
});
```

### To fetch an outgoing sms by id
### To fetch an outgoing SMS by id

```js
var id = 'outgoing-sms-id';
Expand All @@ -82,7 +76,7 @@ promise
});
```

### To fetch a list incoming sms
### To fetch a list of incoming SMS

```js
var promise = smsglobal.sms.incoming.getAll();
Expand All @@ -96,7 +90,7 @@ promise
});
```

### To fetch an incoming sms by id
### To fetch an incoming SMS by id

```js
var id = 'incoming-sms-id';
Expand All @@ -111,8 +105,8 @@ promise
});
```


### To send an OTP

```js
var payload = {
origin: 'from number',
Expand All @@ -131,47 +125,46 @@ smsglobal.otp.send(payload, function(error, response) {
console.log(error);
}
});

```

*Success response object*

```js
```json
{
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'
"statusCode": 200,
"status": "OK",
"data": {
"requestId": "404372541683676561917558",
"destination": "61400000000",
"validUnitlTimestamp": "2025-11-18 17:08:14",
"createdTimestamp": "2025-11-18 16:58:14",
"lastEventTimestamp": "2025-11-18 16:58:14",
"status": "Sent"
}
}
```

*Error response object in the case of validation error*

```js
```json
{
statusCode: 400,
status: 'Bad Request',
data: {
errors: {
message: {
errors: [
'Message template should contain a placeholder for code i.e. {*code*}.'
"statusCode": 400,
"status": "Bad Request",
"data": {
"errors": {
"message": {
"errors": [
"Message template should contain a placeholder for code i.e. {*code*}."
]
}
}
}
}

```

### To cancel an OTP request
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:

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 following are examples of each method:

```js
var id = 'otp-request-id'; // requestId received upon sending an OTP
Expand All @@ -183,6 +176,7 @@ promise.then((response) => {
console.log(error)
});
```

```js
var destination = 'destination-number';
var promise = smsglobal.otp.cancelByDestination(id)
Expand All @@ -196,24 +190,24 @@ promise.then((response) => {

*Success response object*

```js
```json
{
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'
"statusCode": 200,
"status": "OK",
"data": {
"requestId": "404372541683676561917558",
"destination": "61400000000",
"validUnitlTimestamp": "2025-11-18 17:08:14",
"createdTimestamp": "2025-11-18 16:58:14",
"lastEventTimestamp": "2025-11-18 16:58:14",
"status": "Cancelled"
}
}
```

### To verify an OTP code entered by your user

The OTP code entered by your user can be verified by either using `requestId` or `destination number`. The followings are examples of each method:
The OTP code entered by your user can be verified by either using `requestId` or `destination number`. The following are examples of each method:

```js
var id = 'otp-request-id'; // requestId received upon sending an OTP
Expand Down Expand Up @@ -247,22 +241,21 @@ smsglobal.otp.verifyByDestination(id, code, function(error, response) {

*Success response object*

```js
```json
{
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'
"statusCode": 200,
"status": "OK",
"data": {
"requestId": "404372541683676561917558",
"destination": "61400000000",
"validUnitlTimestamp": "2025-11-18 17:08:14",
"createdTimestamp": "2025-11-18 16:58:14",
"lastEventTimestamp": "2025-11-18 16:58:14",
"status": "Verified"
}
}
```


## Running tests

Run the tests:
Expand All @@ -271,7 +264,7 @@ Run the tests:
npm test
```

To run test with code coverage report
To run tests with a code coverage report:

```
npm run mocha-only
Expand All @@ -280,9 +273,10 @@ npm run mocha-only
## Available REST API Resources
* Sms
* Sms Incoming
* OTP (beta)
* OTP

# Reference

[REST API Documentation](https://www.smsglobal.com/rest-api/?utm_source=dev&utm_medium=github&utm_campaign=node_sdk)

For any query [contact us](https://www.smsglobal.com/contact/?utm_source=dev&utm_medium=github&utm_campaign=node_sdk)
10 changes: 2 additions & 8 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@ const smsglobal = require('smsglobal')(SMSGLOBAL_API_KEY, SMSGLOBAL_API_SECRET);
const util = require('util');

// Send sms
var payload = {
const payload = {
origin: 'SMSGlobal',
destination: '61400000000',
message: 'Test sms from node sdk',
};

smsglobal.sms.send(payload, function(error, response) {

if (response) {
console.log('Response:', response.data ? response.data : response);
}

if (error) {
console.log('Error:', util.inspect(error, {showHidden: false, depth: null, colors: true}));
}

});


// fetch a list of outgoing sms
var options = {
const options = {
offset: 1,
limit: 50,
};
Expand All @@ -40,11 +36,9 @@ smsglobal.sms.getAll(options)

// fetch a list of incoming sms
smsglobal.sms.incoming.getAll(function(error, response) {

if (response) {
console.log('Response:', response.data ? response.data : response);
}

if (error) {
console.log('Error:', util.inspect(error, {showHidden: false, depth: null, colors: true}));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/otp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const smsglobal = require('smsglobal')();
const util = require('util');

// To send an OTP request
var payload = {
const payload = {
origin: 'SMSGlobal',
message: '{*code*} is your SMSGlobal verification code.',
destination: '61400000000',
Expand Down
3 changes: 2 additions & 1 deletion lib/Smsglobal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const errors = require('./errors');

/**
* @constructor Smsglobal
*
Expand All @@ -19,7 +20,7 @@ const Smsglobal = function (key, secret) {
process.env['SMSGLOBAL_API_SECRET'] = secret;
}

// check if credetials not supplier in constructor
// check if credentials not supplied in the constructor
if (this.key === undefined || this.secret === undefined) {
throw new Error(errors.smsglobal);
}
Expand Down
Loading