Home > Uncategorized > Download complete #Twilio Pricing table in C#

Download complete #Twilio Pricing table in C#

twilio-730x365

Twilio offer a great service in providing international phone numbers, – and it’s the provider behind CloudAnsweringMachine.com but the price varies greatly like from a $1 number in the US to a $110/month Toll free number in Bulgaria.

So, here is some code that queries the Twilio API to download all countries, and stores the pricing information in a database :

var strUrl = “https://pricing.twilio.com/v1/PhoneNumbers/Countries/?PageSize=100”;
var wc = new WebClient();
wc.Headers[“Content-Type”] = “application/x-www-form-urlencoded”;
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + “:” + password));
wc.Headers[HttpRequestHeader.Authorization] = string.Format(
“Basic {0}”, credentials);
var strCountries = wc.DownloadString(strUrl);
var jCountries = JObject.Parse(strCountries);
foreach(var jCountry in jCountries[“countries”])
{
Console.WriteLine(“Downloading ” + jCountry[“country”].ToString());
try
{
var strCountryUrl = jCountry[“url”].ToString();
var strCountryJson = wc.DownloadString(strCountryUrl);
var jCountryJson = JObject.Parse(strCountryJson);
if (jCountryJson[“price_unit”].ToString() != “USD”) throw new Exception(“Should be usd!”);
foreach (var jPhoneNumber in jCountryJson[“phone_number_prices”])
{
var strSQL = “insert into CAMPricing (country, numberType, price) values (‘{0}’,'{1}’,{2})”;
strSQL = string.Format(strSQL,
jCountryJson[“iso_country”].ToString(),
jPhoneNumber[“number_type”].ToString(),
jPhoneNumber[“current_price”].ToString());
Database.ExecuteNonQuery(strSQL);
}
}
catch(Exception ex)
{
Console.WriteLine(“Failed to download ” + jCountry[“country”].ToString());
Console.WriteLine(ex.ToString());
}

}

And here is the pricing table correct as of time of writing:

ISO Country Number Type Price (USD)
AE toll free 25.00
AR local 8.00
AR toll free 25.00
AT mobile 6.00
AT national 1.00
AT toll free 25.00
AU local 2.50
AU mobile 6.00
AU toll free 15.00
BA local 42.00
BA national 42.00
BB local 27.00
BE local 1.00
BE mobile 1.00
BE national 1.00
BE toll free 25.00
BG local 3.00
BG toll free 110.00
BJ mobile 27.00
BO toll free 25.00
BR local 4.00
BR toll free 35.00
BW toll free 50.00
BY toll free 25.00
CA local 1.00
CA toll free 2.00
CH local 1.00
CH mobile 8.00
CH toll free 25.00
CL local 7.00
CL mobile 10.00
CO local 14.00
CO toll free 25.00
CY national 5.00
CZ local 1.00
CZ mobile 12.00
CZ national 1.00
CZ toll free 35.00
DE local 1.00
DE mobile 5.00
DE national 1.00
DE toll free 25.00
DK local 1.00
DK toll free 25.00
DO local 7.00
DZ local 33.00
DZ national 33.00
EC local 34.00
EE local 1.00
EE mobile 3.00
EE national 1.00
ES local 2.00
ES mobile 4.00
ES national 2.00
ES toll free 25.00
FI local 1.00
FI national 1.00
FI toll free 40.00
FR local 1.00
FR mobile 2.50
FR national 1.00
GB local 1.00
GB mobile 1.00
GB national 1.00
GB toll free 2.00
GD local 27.00
GE local 14.00
GE national 14.00
GH mobile 27.00
GN mobile 27.00
GR local 1.00
GR toll free 25.00
GT local 31.00
GT mobile 28.00
HK mobile 15.00
HK national 6.00
HK toll free 25.00
HR local 5.00
HR mobile 6.00
HU local 4.00
HU mobile 25.00
ID local 23.00
ID mobile 3.00
ID toll free 25.00
IE local 1.00
IE mobile 6.00
IE national 1.00
IE toll free 25.00
IL local 4.00
IL mobile 14.00
IL national 4.00
IL toll free 25.00
IS local 1.00
IT local 1.00
IT mobile 25.00
JM local 27.00
JP local 4.50
JP national 4.50
JP toll free 25.00
KE local 16.00
KR local 3.00
KR national 3.00
KR toll free 25.00
KY local 29.00
LT local 1.00
LT mobile 3.00
LU local 3.00
LV local 1.00
LV mobile 3.00
ML local 38.00
MO mobile 70.00
MT national 5.00
MU mobile 43.00
MX local 5.00
MX toll free 30.00
MY mobile 5.00
MY toll free 25.00
NA local 33.00
NA national 33.00
NL local 3.00
NL mobile 5.00
NL national 3.00
NL toll free 25.00
NO local 3.00
NO mobile 12.00
NO toll free 25.00
NZ local 3.00
NZ toll free 40.00
PA local 8.00
PE local 6.00
PH local 15.00
PH toll free 25.00
PL local 1.00
PL mobile 3.00
PL toll free 25.00
PR local 3.00
PT mobile 15.00
PT national 1.00
PT toll free 25.00
RO local 3.00
RO toll free 25.00
RS toll free 105.00
SE local 1.00
SE mobile 1.00
SE national 1.00
SE toll free 25.00
SG mobile 75.00
SI local 5.00
SK local 1.00
SK toll free 25.00
SV local 7.00
TH local 25.00
TH toll free 25.00
TN local 35.00
TN national 35.00
TT local 27.00
TZ local 27.00
TZ national 27.00
UG local 28.00
UG national 28.00
UG toll free 25.00
US local 1.00
US toll free 2.00
VN local 36.00
ZA national 1.50
ZA toll free 25.00
Advertisement
Categories: Uncategorized
  1. June 7, 2018 at 12:24 pm

    For some reason NG, TW and VE don’t return any results … but confused at that?

    Like

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: