微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 curl 或 Postman 向多个收件人发送短信

如何解决使用 curl 或 Postman 向多个收件人发送短信

我无法使用 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 中可以完美地发送到多个号码(截图) (screenshot)

在 postman 下的 Body > Form-data 中为每个数字输入一个 ToBinding 键值对。在键字段中输入“ToBinding”,在值字段中输入以下电话号码语法。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。