10
votes

I'm getting the following error when I try to place calls using the Twilio REST API.

https://www.twilio.com/docs/api/rest

HTTP/1.1 401 Unauthorized 
Server: nginx 
Date: Thu, 10 May 2012 16:50:48 GMT 
Content-Type: application/xml 
Connection: close 
WWW-Authenticate: Basic realm="Twilio API" 
Etag: 
Last-Modified: 
Content-Length: 233 

401 Authenticate 20003 
http://www.twilio.com/docs/errors/20003

I googled, but found nothing. Anyone had this issue?

What I POSTed on the API call was:-

$url = 'https://api.twilio.com/2010-04-01/Accounts/ACdxxxxxxx/Calls';

From => +1415xxxxxx 
To => +1646xxxxx
Url => http://173.201.xx.xx/Test/Twilio/twilio_test.php
5
Hi, You need to authenticate your request with your Account Sid and Auth Token. See the curlopt_userpwd setting here: php.net/manual/en/function.curl-setopt.php#98164 - Kevin Burke
@KevinBurke Thanks, that was it. I provided the Auth Token through curlopt_userpwd and it worked. - Sparky

5 Answers

7
votes

(Twilio employee here.)

The 401 error is usually related to when you are supposed to authenticate but haven't or potentially an error occurred with it.

Can you provide the full snippet of code that you're using to place the call? Are you using one of our sample snippets or something else?

6
votes

It seems there are a few causes for this error. I discovered I receive an "Authenticate" error when my account funds have been depleted. When I added funds, it worked again without any problems.

2
votes

Your Sid and Token must be wrong. Check your config file.

0
votes

Just adding a more recent response. I ran into this issue when I created a new Twilio account to use just for SMS. My account was suspended which was causing the issue.

The email address I used to create the account is not one that I monitor, but they sent me an email asking for details about my intended use and how I plan to allow users to opt in and opt out. Since I had not responded, the account was suspended.

0
votes

This same problem happened to me. I had made some successful API requests and reached a stopping point in my App, and I decided to publish to GitHub. Moments later I tried running my App, and my server was crashing when I made my Twilio API requests; and the console was saying I needed to authenticate. It turns out I had not added my .env to the .gitIgnore and I unknowingly published my accountSid to GitHub. Twilio sensed this and immediately suspended my accountSid. I am waiting for them to generate a new accountSid for me.