Issue
If I run this:
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_CONNECTED_APP_SID'/AuthorizedConnectApps/CN***.json' -u "$TWILIO_CONNECTED_APP_SID:$TWILIO_CONNECTED_AUTH_TOKEN" -sS | jq
I can see that my app is authorized:
{
"connect_app_sid": "CN***",
"account_sid": "AC***1",
"permissions": [
"get-all",
"post-all"
],
"connect_app_friendly_name": "*** Dev Connect App",
"connect_app_description": "*** test account",
"connect_app_company_name": "***",
"connect_app_homepage_url": "https://***.com/",
"uri": "/2010-04-01/Accounts/AC***/AuthorizedConnectApps/CN***.json"
}
But when I try to list all the phone numbers for that account using my app credentials:
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_CONNECTED_APP_SID'/IncomingPhoneNumbers.json' -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" -sS | jq
I get:
{
"code": 20003,
"detail": "",
"message": "Authenticate",
"more_info": "https://www.twilio.com/docs/errors/20003",
"status": 401
}
I can't figure out why. I know those credentials work because I can list my subaccounts:
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts.json?Status=active' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN -sS | jq
I just can't seem to get any info for my connected accounts.
Solution
Twilio developer evangelist here.
When you make a request on behalf of an account that is connected through Twilio Connect you should authenticate the request with the connected account's SID but your auth token. The account's SID also goes into the URL for API requests under the 2010-04-01
namespace.
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_CONNECTED_APP_SID'/IncomingPhoneNumbers.json' \
-u "$TWILIO_CONNECTED_APP_SID:$TWILIO_AUTH_TOKEN" -sS | jq
Answered By - philnash