Craig
Craig

Reputation: 36826

Get price of phone number from Twilio

I am trying to get the price of a phone number in Twilio. I have this to get the phone numbers

var localAvailableNumbers = Twilio.Rest.Api.V2010.Account.AvailablePhoneNumberCountry.LocalResource.Read("US");

And this to get the prices

var prices = Twilio.Rest.Pricing.V1.PhoneNumber.CountryResource.Fetch("US");

But I can't see any way to map each of the phone numbers to a price?

This is an example of the response from the phone numbers request

{
  "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/AvailablePhoneNumbers\/US\/Local.json?AreaCode=510",
  "available_phone_numbers": [
    {
      "friendly_name": "(510) 564-7903",
      "phone_number": "+15105647903",
      "lata": "722",
      "rate_center": "OKLD TRNID",
      "latitude": "37.780000",
      "longitude": "-122.380000",
      "region": "CA",
      "postal_code": "94703",
      "iso_country": "US",
      "capabilities":{
        "voice": true,
        "SMS": true,
        "MMS": false
      },
      "beta": false
    }
  ]
}

Nowhere does it tell me if this is local, mobile, toll free etc.

Upvotes: 1

Views: 555

Answers (2)

Craig
Craig

Reputation: 36826

I found the problem. For the different phone number types I need to make different queries.

// Local numbers
var numbers = LocalResource.Read("US");

// Mobile numbers
var numbers = MobileResource.Read("US");

Upvotes: 0

Devin Rader
Devin Rader

Reputation: 10366

Phone numbers are priced by location and type, so all phone numbers in [Country] of [Type] will be the same price.

In your code above you are querying the Pricing API for US phone number prices so you'll get two PhoneNumberPrice records back that tell you the price of local and toll free numbers, each of which has a NumberType property that tells you the type of number the price applies to. If you made the same query for another country like the UK you might get local, mobile, national and toll free prices.

var country = Twilio.Rest.Pricing.V1.PhoneNumber.CountryResource.Fetch("US");
var prices = country.PhoneNumberPrices;
foreach(var price in prices) 
{
    Console.Writeline(price.NumberType.ToString());
}

Now, when you know the price for the country and type, you can query for available phone numbers of one of those types. In your code above your asking for Local US phone numbers which will all be $1/month.

Hope that helps.

Upvotes: 1

Related Questions