papichulo
papichulo

Reputation: 21

Send SMS to multiple recipients with curl or Postman

I have not been able to send SMS to multiple numbers with Twilio Notify using Postman. Does anyone know a correct syntax for two numbers I could try?

If I enter just one number in the value field for the ToBinding parameter it works

{"binding_type":"sms", "address":"+1651000000000"}

but if I try entering two numbers like this

['{"binding_type":"sms", "address":"+1651000000000"}',
'{"binding_type":"sms", "address":"+1651000000000"}']

I get the error:

{"code": 20001, 
"message": "Can not convert incoming parameters to Notification object: Parameter 'ToBinding' is invalid", 
"more_info": "https://www.twilio.com/docs/errors/20001", 
"status": 400}

Yes, I have seen How to Send SMS Messages to Multiple Recipients with Twilio Notify? but it does not answer my question as it is creating an array in a language to passthrough and I just want to do a simple test with Postman.

Upvotes: 2

Views: 1222

Answers (2)

papichulo
papichulo

Reputation: 21

This worked perfectly in Postman for sending to multiple numbers (screenshot) (screenshot)

In postman under Body > Form-data enter a ToBinding key value pair for each number. In the key field enter "ToBinding" and the value field enter the following syntax for a phone number.

{"binding_type":"sms", "address":"+1651000000000"}

Upvotes: 0

Alan
Alan

Reputation: 10771

Here is he cURL syntax:

curl -X POST https://notify.twilio.com/v1/Services/IS.../Notifications \
--data-urlencode 'ToBinding={"binding_type":"sms", "address":"+1407xxxxxx"}' \
--data-urlencode 'ToBinding={"binding_type":"sms", "address":"+1802xxxxxx"}' \
-d 'Body=Hello World!' \
-u 'AC...:AUTH_TOKEN' | json_pp

For anyone curious, below is Node code for doing same:

const fetch = require('node-fetch');

const params = new URLSearchParams();
params.append('Body', 'Hello from Node-Fetch - IT WORKS!!!');
params.append('ToBinding', '{ "binding_type": "sms", "address": "+1407xxxxxx" }');
params.append('ToBinding', '{ "binding_type": "sms", "address": "+1802xxxxxx" }');

let headers = {Authorization: 'Basic ' + new Buffer.from(process.env.TWILIO_ACCOUNT_SID + ":" + process.env.TWILIO_AUTH_TOKEN).toString("base64")};

console.log(`To String Output: ${params.toString()}`);

fetch('https://notify.twilio.com/v1/Services/IS.../Notifications',
    {method: 'POST', headers: headers, body: params})
    .then(res => res.json())
    .then(json => console.log(json))
    .catch(err => console.log(err))

Upvotes: 1

Related Questions