The Twilio REST API is an HTTP-based API that requires secure connections over the public internet. Use these tools and techniques as a companion guide when configuring your environment and troubleshooting connection issues.
Twilio Status Page
If you suspect there is an issue with the Twilio REST API, be sure to check our status page for any platform-wide notices.
Debugging in the Helper Libraries
To assist with debugging, the Twilio helper libraries allow you to access the underlying request and response objects, including all the headers. This capability is built into the default HTTP client that ships with the libraries.
For example, to track down the source of latency, you can retrieve the custom Twilio header Twilio-Request-Duration to see how long in seconds the request took to process on our platform.
Here’s an example using our PHP helper library:
<?php
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
$sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'your_auth_token';
$client = new Client($sid, $token);
$message = $client->messages->create("+14158675309", array(
'From' => "+14258675310",
'Body' => 'Ahoy!'
));
/* Retrieve the last response from the HTTP client and inspect the Twilio-Request-Duration header */
echo($client->getHttpClient()->lastResponse->getHeaders()["Twilio-Request-Duration"]);
If your request took much longer than the Twilio-Request-Duration header reported, there is likely a delay in your local network or your ISP is having issues.
Enable SSL/TLS Debugging
The Twilio REST API requires secure connections. When debugging SSL/TLS errors, you may need to get lower-level details from your HTTP client, if supported, to fully diagnose and resolve the issue.
Here is an example of enabling low-level debugging for Java: Debugging SSL/TLS Connections.
Diagnostic Tools and Utilities
There are many different tools and utilities you can use to diagnose connection issues. Here are some suggestions.
Notice: The specific IP addresses in your output may be different than the examples below due to dynamic IP assignment within our cloud infrastructure.
dig
Use dig DNS query tool to troubleshoot DNS resolution. If you see status: NXDOMAIN in the response, there is likely a problem with your DNS provider.
$ dig api.twilio.com
; <<>> DiG 9.8.3-P1 <<>> api.twilio.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51922
;; flags: qr rd ra; QUERY: 1, ANSWER: 9, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;api.twilio.com. IN A
;; ANSWER SECTION:
api.twilio.com. 2 IN CNAME prod-api-us1-308668521.us-east-1.elb.amazonaws.com.
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 34.226.13.167
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 52.4.111.215
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 34.233.223.114
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 50.17.170.178
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 52.22.195.204
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 34.230.110.42
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 35.171.173.132
prod-api-us1-308668521.us-east-1.elb.amazonaws.com. 5 IN A 34.234.152.191
;; Query time: 86 msec
;; SERVER: 192.168.208.1#53(192.168.208.1)
;; WHEN: Tue Jul 17 17:41:17 2018
;; MSG SIZE rcvd: 221
openssl
Use openssl to troubleshoot SSL/TLS related issues. If you receive an error, check the specific error code to determine the underlying issue. Be sure your openssl library is up to date and that you are referencing the correct location of your local trust store to verify our certificate.
$ openssl s_client -connect api.twilio.com:443 -quiet -CAfile cacert.pem
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = Thawte RSA CA 2018
verify return:1
depth=0 C = US, ST = California, L = San Francisco, O = "Twilio, Inc.", CN = *.twilio.com
verify return:1
curl
Use curl as a general purpose tool for testing connectivity to the REST API. If you encounter an error, check the specific error code to determine the underlying issue.
$ curl https://api.twilio.com/ -v
* Trying 54.175.110.232...
* Connected to api.twilio.com (54.175.110.232) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.twilio.com
* Server certificate: thawte SSL CA - G2
* Server certificate: thawte Primary Root CA
> GET / HTTP/1.1
> Host: api.twilio.com
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< 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
< Content-Type: application/xml
< Date: Wed, 18 Jul 2018 01:11:48 GMT
< Strict-Transport-Security: max-age=15768000
< Twilio-Request-Duration: 0.001
< Twilio-Request-Id: RQ09370f289cef4fc7bec3e605a68be499
< X-Powered-By: AT-5000
< X-Shenanigans: none
< Content-Length: 254
< Connection: keep-alive
Fiddler
Use Fiddler as a multipurpose web debugging proxy to intercept and inspect requests while running your application. This can be useful for capturing issues that are intermittent or don't reveal themselves via the other tools and utilities.
Ping
The site api.twilio.com
no longer responds to ping requests. We suggest using one of the options explained above instead.
Twilio Customer Support
For additional assistance diagnosing connection issues to our REST API, please contact Twilio Customer Support.