bg-gradient-blue
Jul, 22 2021

Send Bulk SMSs to your devices with Postman

blog

When you need to deploy a bunch of tracking devices at once, it's much easier to configure them in bulk. That said, attaching them to a configurator and downloading the right file can still be very tedious. SMS configuration is your hero here. And what's better than SMS configuration? Well, bulk SMS configuration!

In this post, I'm going to show you just how easy it is to send an SMS to multiple devices using the EMnify API and Postman.

To send an SMS to multiple endpoints, you can use the software Postman which allows you to test and run EMnify’s Rest-API calls and perform operations in bulk, such as:

  • Register SIMs via API

  • Create Multiple Endpoints via API

  • Update SIMs via API

    • Activate one SIM

    • Activate multiple SIMs

The EMnify Rest-API can be found under the EMnify Developer Hub. Now every time you want to use the EMnify API, you need to authenticate it. You can either get the authentication token with your EMnify credentials (username and password used to log into the EMnify portal) or with an Application Token which is more secure.

Application Token

To generate an application token, log in to your EMnify portal.
Go to Integrations> Scroll down to Application Token > Click on ADD TOKEN

Copy the token to use it in Postman.

Now open Postman and click on Environments. Create a new environment and give it a name. Under VARIABLE, add api_key and paste the token copied from the EMnify portal under INITIAL VALUE.

Click on Save and you are ready to get your Authentication Token.

Screenshot 2021-07-22 at 12-44-29-png

Authentication

The API call to generate the Authentication Token is:

POST    URL: https://cdn.emnify.net/api/v1/authenticate

Headers: Content-Type: application/json

Body :(Click on "Raw")

{
"application_token": "YOUR_APPLICATION_TOKEN"
}

As we have saved the application token as a variable, we can use it here by selecting the saved Environment from in the previous step and replacing YOUR_APPLICATION_TOKEN with .

Selecting Environment

Now click on Send and generate the Authentication Token.

Sending an SMS to multiple endpoints

To send an SMS to multiple endpoints add a Collection and create a Request for the API call.

Based on the API documentation Swagger, we see that the API call to send an SMS to an endpoint is

POST    URL: https://cdn.emnify.net/api/v1/endpoint//sms

In the request created in Postman, we need to add:

Headers: 

  1. Content-Type: application/json
  2. Authorization: Bearer space (Copy&Paste the generated Authentication Token)

Body:  (click on “Raw”)

{
  "source_address"12345689,
  "payload""This is the message text"
}

In case you don't want to copy & paste the Authentication Token in the API call manually, you can create a variable at run time.

Go to Tests in the Authentication API call and add the following in the box below.

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable(“Auth_Token”,jsonData.auth_token)

Don´t forget to save the changes.

adding Tests

By doing so, a variable will be created in your current environment, and it will receive the value of the Authentication Token. 

You can now modify the Send SMS API call Authorization Header using this variable.

Authorization: Bearer

Auth_token variable

Running the API call for multiple devices

To run the API call for multiple devices you have to click on “Runner” on the bottom of the platform. Or you can select the collection and click on Run. Select the "Send SMS to Device" call that you saved in the previous step.Running bulk sms

Regarding the criteria:

Iterations: The number of devices you want to send this SMS to. It is the number of rows from the endpoint_id list you will upload.

Delay: Delay time between calls: The best practice is to have a delay of 1000ms between each API call regardless if its bulk or for only for a few calls.

Select file: Upload the file with the ID of the devices.

To get the list of all your devices, login to your portal and navigate to Reports. Click on the tag  Device List and download the data using the hamburger menu on the right.
device List

Delete all the other columns and just keep the Endpoint ID column. Make sure it is named "endpoint_id" and upload it to the Runner.

Before you run the API call make sure that you have done the following in the EMnify Portal:

  1. SMS exchange activated (MO/MT enabled)
  2. Breakout region with (VPN)

Now you can Run Bulk Messaging on your devices.

How to check that the SMSs are sent

Postman: You can check the results in Postman.
You should receive 201 as the response after Running the bulk SMS order in the Runner window.

bulk sms successful

EMnify Portal: You can also see the status of the SMSs from the SMS console.
Check SMS in portal

So, there it is. A simple way to send SMS in bulk to your devices using the EMnify API and Postman. Go ahead and try it out. If you don't have an account yet, get one for free at www.portal.emnify.com.

Stay Connected!

Download your eSIM now and get started