2

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.

BSMP
  • 4,596
  • 8
  • 33
  • 44
papichulo
  • 21
  • 1
  • Can you try using double-quotes instead of single quotes and escape the inner double quotes using backslash? e.g. `["{\"binding_type\":\"sms\", \"address\":\"+1651000000000\"}", "{\"binding_type\":\"sms\", \"address\":\"+1651000000000\"}"]` – Vimanyu May 12 '21 at 02:49
  • Thanks Vimanyu, unfortunately it still gave the same 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}" – papichulo May 12 '21 at 13:51

2 Answers2

1

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))
Alan
  • 10,465
  • 2
  • 8
  • 9
  • I believe that the OP was looking to put this in the Postman. From the Twilio docs, `--data-urlencode` parameters would fit as `x-www-form-urlencoded` Body type and `ToBinding` as key. But it'll break when you have multiple `ToBinding` keys. ref: https://www.twilio.com/blog/send-test-http-requests-twilio-sms-postman – Vimanyu May 12 '21 at 02:55
  • 1
    Thanks Alan. Good news , even though I was looking for Postman (My fault I did write cURL in the topic) my issue is solved from looking at your cURL example. After seeing in the cURL example that you pass a ToBinding= for each number I tried just adding another ToBinding form field in Postman for the second number and it worked. Thanks to you both! – papichulo May 12 '21 at 14:18
0

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"}
Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
papichulo
  • 21
  • 1
  • 1
    Welcome to Stack Overflow. We prefer answers that show more than just a link. Pleae [edit] yours. – O. Jones May 12 '21 at 21:32