通过Twilio发送短信,让它选择带有MessagingServiceSid的发件人号码不起作用

时间:2016-07-28 15:12:08

标签: twilio

我尝试使用twilio发送短信,但未指定特定的发件号,而是让Copilot为我选择最佳号码(如https://www.twilio.com/docs/api/rest/sending-messages#post-parameters-conditional中所述)。

但是,在发送请求时,Twilio REST API会抱怨我没有指定From号码。正如预期的那样,指定From编号有效。但我希望避免这种情况更灵活,以防我需要更多数字。我误解了文档吗?

我使用HTTPie来测试API。完整的请求/回复:

$ http --print=HBhb --form POST 'https://$ACCOUNT_SID:$ACCOUNT_TOKEN@api.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/SMS/Messages.json' MessagingServiceSid=$SERVICE_SID To=$PHONE Body=Hello

POST /2010-04-01/Accounts/$ACCOUNT_SID/SMS/Messages.json HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: Basic REDACTED
Connection: keep-alive
Content-Length: 83
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: api.twilio.com
User-Agent: HTTPie/0.9.2

MessagingServiceSid=$SERVICE_SID&To=$PHONE&Body=Hello

HTTP/1.1 400 BAD REQUEST
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since
Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Connection: keep-alive
Content-Length: 136
Content-Type: application/json
Date: Thu, 28 Jul 2016 14:54:38 GMT
Twilio-Request-Duration: 0.056
Twilio-Request-Id: RQ5b9acf9d222947668fa9ada38d5beaba
X-Powered-By: AT-5000
X-Shenanigans: none

{
    "code": 21603, 
    "message": "A 'From' phone number is required.", 
    "more_info": "https://www.twilio.com/docs/errors/21603", 
    "status": 400
}

1 个答案:

答案 0 :(得分:1)

我可以看到您在MessageService中有一个数字,但看起来您正在使用不支持sending with the MessageService的旧弃用端点。

你有:/2010-04-01/Accounts/$ACCOUNT_SID/SMS/Messages.json

您应该使用:/2010-04-01/Accounts/$ACCOUNT_SID/Messages.json

尝试一下,让我知道它是怎么回事。