问题描述
我无法使用 Postman 通过 Twilio Notify 向多个号码发送短信。有人知道我可以尝试的两个数字的正确语法吗?
如果我在 ToBinding
参数的值字段中只输入一个数字,它会起作用
{"binding_type":"sms","address":"+1651000000000"}
但是如果我尝试输入两个这样的数字
['{"binding_type":"sms","address":"+1651000000000"}','{"binding_type":"sms","address":"+1651000000000"}']
我收到错误:
{"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}
是的,我见过 How to Send SMS Messages to Multiple Recipients with Twilio Notify? 但它没有回答我的问题,因为它正在用一种语言创建一个数组来传递,我只想用 Postman 做一个简单的测试。
解决方法
这是他的 cURL 语法:
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
对于任何好奇的人,以下是用于执行相同操作的 Node 代码:
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',"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))
,
在 postman 下的 Body > Form-data 中为每个数字输入一个 ToBinding 键值对。在键字段中输入“ToBinding”,在值字段中输入以下电话号码语法。
{"binding_type":"sms","address":"+1651000000000"}