Search code examples
twiliotwilio-php

twillio - hot get the price of a number?


I need to get the price of each phone number, as it was in their "Buy a number" page https://www.twilio.com/user/account/phone-numbers/search

Variable $number do not contain such info.

$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
        "AreaCode" => "510"
    ));
foreach($numbers->available_phone_numbers as $number) {
    echo $number->phone_number;
}

Solution

  • Ricky from Twilio here.

    You can access pricing information using our Pricing API. This will let you query by country:

    $client = new Pricing_Services_Twilio($AccountSid, $AuthToken);
    $country = $client->phoneNumberCountries->get("US");
    
    foreach ($country->phone_number_prices as $p) {
        echo $p->number_type . " " . $p->current_price . "\n";
    }
    

    You can then use that information to properly assign the pricing with numbers you retrieve with the Available Phone Numbers API call.