Twexit API - Node.js

Connecting to Notifyre via the Twexit API using Node.js

Twilio users can easily make the switch to Notifyre and save on their SMS messaging costs via the Twexit API. The Twexi API allows users to send SMS messages via Notifyre with minimal changes to existing Twilio SMS API code.

Setting up your account

To use the Twexit API, please ensure that you have signed up for a free Notifyre account, then follow the steps below. 

Verify your phone number 

  1. Login to the Notifyre dashboard 
  2. If you are a first-time Notifyre user, click on the blue notification "Please verify your phone number here" to be redirected to your Profile page. Alternatively, click on your name in the top right hand corner of the dashboard and select "Profile" from the drop-down menu
  3. Enter your mobile number into the Phone Number field and click "Verify Number"
  4. You'll receive an SMS verification code. Enter the SMS code into the pop-up window and click "Verify Number"

Generate an API token 

  1. Navigate to the settings tab on the right side of the Notifyre dashboard and click "Developer" from the drop-down menu
  2. Select the "API Tokens" tab and click "+New"

See: how to create an API token

Find your account ID

When setting up the Twexit API, you'll need your Notifyre account ID. To find this, simply:

  1. Navigate to the settings tab on the right side of the Notifyre dashboard and click "Account" from the drop-down menu
  2. On the "General" tab you'll be able to view your account ID

Using a virtual mobile number

You have the option to use a dedicated virtual mobile number to send and receive SMS via the Twexit API. If you do not setup a virtual mobile number, you will be unable to receive SMS replies.

See: adding a virtual mobile number to your account.

Using a custom SMS sender ID 

You have the option to use a custom alphanumeric sender ID as the sender (from) when sending SMS via the Twexit API. In this case, you will not be able to receive SMS replies from your audience.

See: setting up a custom SMS sender ID on your account.

Sending an SMS message

To start sending SMS via the Twexit API, you must update the Request URL, the account ID and the API token in your existing Twilio API. 

1. Update the request URL 

To update the request URL, you will need to replace the existing HTTP POST URL:

https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json

with Notifyre's Twexit API URL in the Send SMS API endpoint:

https://twilio.api.notifyre.com/Accounts/${notifyreaccountSid}/Messages.json

2. Update the account ID 

To update the account ID, you will need to replace the variable TWILIO_ACCOUNT_SID with your Notifyre account ID. We recommended creating a new variable called NOTIFYRE_ACCOUNT_ID and replacing the Twilio variable with the Notifyre one in the Send SMS API endpoint. Alternatively, you can hardcode your Notifyre account ID.

3. Update the API token

To update the API token, you will need to replace the variable TWILIO_AUTH_TOKEN with your Notifyre API token. We recommend creating a new variable called NOTIFYRE_API_TOKEN and replacing the Twilio variable with the Notifyre one in the Send SMS API endpoint. Alternatively, you can hardcode your Notifyre API token.

Node.js code samples

Sample Node.js Javascript code in the Send SMS API endpoint with Twexit API updated variables: Request URL, Account ID and API token.

Original Twilio Send SMS API call:

const request = require('request');
const accountSid = 'TWILIO_ACCOUNT_SID';
const authToken = 'TWILIO_AUTH_TOKEN'
request.post(`https://api.twilio.com/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`, {
headers: {
'Authorization': 'Basic ' + Buffer.from(`${accountSid}:${authToken}`).toString('base64'),
},
form: {
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
from: '+15017122661',
to: '+15558675310'
}
}, (err, _, body) => {
console.error('Send SMS error', err)
console.error('Send SMS response', body)
})

Updated Notifyre Twexit SMS API call: 

const request = require('request');
const accountSid = 'TWILIO_ACCOUNT_SID';
const authToken = 'TWILIO_AUTH_TOKEN'
const notifyreaccountSid = 'NOTIFYRE_ACCOUNT_ID' ;
const notifyreauthToken = 'NOTIFYRE_AUTH_TOKEN' ;

request.post(`https://twilio.api.notifyre.com/Accounts/${notifyreaccountSid}/Messages.json`, {
    headers: {
        'Authorization': 'Basic ' + Buffer.from(`${notifyreaccountSid}:${notifyreauthToken}`).toString('base64'),
    },
    form: {
        body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
        from: '+15017122661',
        to: '+15558675310'
    }
}, (err, _, body) => {
    console.error('Send SMS error', err)
    console.error('Send SMS response', body)
})

Responses are the same as Twilio's responses. The response should contain: 

{
    "error_code": null,
    "num_media": "0",
    "price_unit": "AUD",
    "subresource_uris": {},
    "uri": "",
    "api_version": "1.2.1",
    "account_sid": "{NOTIFYRE_ACCOUT_ID}",
    "sid": "ad85b548-9206-4d2c-b6e1-74ef2960a8b2",
    "body": "Test message from twilio adapter",
    "date_created": "Wed, 10 Aug 2022 01:15:19 +0000",
    "date_sent": null,
    "date_updated": null,
    "direction": "outbound-api",
    "error_message": "",
    "from": "Shared Number (+15017122661)",
    "messaging_service_sid": "22746a6e-f0c0-4075-88f6-5010e9050ebe",
    "num_segments": "1",
    "price": "0.05",
    "status": "sending",
    "to": "+15558675310"
}

Current limitations

  • The Twexit API does not currently support custom URL Callbacks
  • The Twexit API currently only supports the SMS Send API call
  • If using a Notifyre system number to send SMS, you will not be able to receive SMS replies (only available when using a dedicated virtual mobile number)