EchoLogic EchoLogic - 2 months ago 36
PHP Question

Twilio lookup API not working?

I'm trying to use Twilio's Lookup API to get certain properties of a mobile number via PHP... with very little success:

$twilioClient = new Lookups_Services_Twilio(Credential::TwilioSID, Credential::TwilioToken);
$number = $twilioClient->phone_numbers->get($someNumber);


Note that this is the example code present within their 'Getting Started' page here.

By taking a look at
$number
in the debugger, I can confirm it is returning something:

enter image description here

The highlighted property of the object is simply recursive with no new information.

Attempting to evaluate
$number->phone_number
returns
null
. I have tried this with perhaps half a dozen completely valid numbers now and this is the only response I get.

Attempting to
json_encode($number)
returns
false
.

I have no idea why this is not working, but it'd be helpful if I could know what I'm doing wrong.

Answer

I'm just gonna go ahead and assume the phone numbers you've tried are neither from the US, nor in international format.

From Twilio's Lookups Quickstart Tutorial:

You'll want to include the country code of the phone number that you would like formatted. If not included, the country code will default to the US.

So your lookup should probably look like:

$number = $twilioClient->phone_numbers->get($someNumber, array('CountryCode' => 'NZ'));

If the phone numbers are from the US, in international format, or if the above still does not work, try whether the lookup succeeds on Twilio's web interface (you'll need the international prefix there).

If it does, your software library might be broken or your Twilio account might have incorrect/broken access rights.

If the web lookup fails as well, you should contact Twilio and report the issue.

Comments