Sending SMS in twilio returns 21603 : A 'From' number is required

这一生的挚爱 提交于 2019-12-04 04:35:27

问题


This is a regular funded account - It will insist there is no From Number - I also tried as request parameters rather than request body, SID and TOKEN are correct, tested by modifying them and getting appropriate error. Works fine with the twilio libraries, not as a standalone POST

POST /2010-04-01/Accounts/ACCOUNT_SID/Messages.json HTTP/1.1
Host: ACCOUNT_SID:AUTH_TOKEN@api.twilio.com
Content-Type: text/json
Cache-Control: no-cache

{ "body": "Jenny please?! I love you <3", "From": VALID_TWILIO_NUMBER, "to": MY_CELL }

Also I would like to specify the ACCOUNT_SID and AUTH_TOKEN as header parameters, but Twilio does not recognize them.


回答1:


The following works (from POSTMAN history)

POST /2010-04-01/Accounts/ACCOUND_SID/Messages.json HTTP/1.1
Host: api.twilio.com
Authorization: Basic Base64_encoding(ACCOUNT_SID:AUTH_TOKEN)
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

Body=%22Test+1+-+urlencoded%22&From=%22%2BVALID_TWILIO_NUMBER%22&To=%22%2BMY_CELL%22

A few observations: This worked using POSTMAN in Chrome and HTTPRequester in Firefox (Authorization entered interactively through user/passwd dialog)

The Body, From, and To parameters MUST be spelled that way, if the first letter is lowercase, it will return the above error or similar.

That was the only Content-Type that worked - could not get it to work with a JSON request body (the way I posed it on the original question) - that remains an open issue.




回答2:


I suggest that you use request parameters:

$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/AC5ef8732a3c49700934481addd5ce1659/Messages.json \
    -d "Body=Jenny%20please%3F%21%20I%20love%20you%20<3" \
    -d "To=%2B15558675309" \
    -d "From=%2B14158141829" \
    -d "MediaUrl=http://www.example.com/hearts.png" \
    -u 'AC5ef8732a3c49700934481addd5ce1659:{AuthToken}'

Additionally, I have seen that "No From Parameter" error when the phone number is not properly formatted.




回答3:


I was trying to do this with Twilio's new WhatsApp messaging and was running into the same issue. Content-type was important, but also how the body of the POST request was formatted.

From=whatsapp:%2B441618507453&To=whatsapp:%2B17796758684&Body=Your appointment is coming up on {{July 21}} at {{3PM}}

Note the use of URL encoding for "+" symbols



来源:https://stackoverflow.com/questions/23617722/sending-sms-in-twilio-returns-21603-a-from-number-is-required

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!