Home > Blockchain >  Twilio cannot check available numbers
Twilio cannot check available numbers

Time:12-03

I'm using the code directly from Twilio's webpage for getting available phone numbers and I'm getting an error back about a json not being found.

The command is:

curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_ACCOUNT_SID'/AvailablePhoneNumbers/US/TollFree.json?PageSize=20' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

The response is:

{
  "code": 20404, 
  "message": "The requested resource /2010-04-01/Accounts/SK*******************************/AvailablePhoneNumbers/US/TollFree.json was not found", 
  "more_info": "https://www.twilio.com/docs/errors/20404", 
  "status": 404
}

Looking into the error 20404 here seems like the issue is mostly just it's not formatted properly (bad SID, incorrect path, etc.). I don't believe any of these issues pertain to my problem, but I don't know what to do to fix this either. Any ideas as to what I'm doing wrong or what I have setup incorrectly?

CodePudding user response:

The solution is that I was using the incorrect authentication information. I assumed I was to make an api key associated with my account and use that SID and authentication token. That was incorrect and I was supposed to just use the account SID and account authentication token.

So if you run into this problem, make sure you're not using the api key information.

CodePudding user response:

Twilio developer evangelist here.

I see you've answered your own question here, but I wanted to add more detail.

When making API requests to the Twilio API you can authenticate using either the Account SID and Auth Token that is available on your Twilio console dashboard or using an API Key and Secret that you can generate in the console.

But, it has to be noted that the API Key is not the Account SID. In a request to the URL https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_ACCOUNT_SID'/AvailablePhoneNumbers/US/TollFree.json?PageSize=20 requires the actual Twilio Account SID, even if you are using an API Key and Secret to authenticate the request.

  • Related