International Dialling Code

Find out which telephone prefix code is required to call another country

A country has a unique dialling code that must be used at the beginning of any telephone number, in order to make a successful call to a person or business in that country when calling from elsewhere in the world. For example, the international dialling code for the UK is +44, therefore the usual format for dialling our offices in the UK from abroad would be +44 (0)1904 217765.

This is an essential service for any organisation needing to make international calls to it’s customers or suppliers around the world. Our method can be incorporated into internal systems such as purchasing software, CRM and telemarketing systems to help provide staff with correct international dialling codes, thus saving time.

Any company with a customer account/registration section on their website can also benefit, through the pre-populating of input forms on websites and apps with the international dialling code once the customer has completed their address. This not only saves the customer time but also ensures greater accuracy of the telephone information for any future customer service and marketing activity.

API method to use: country_dial

How it works

When a country name is supplied, this method will return the international dialling code prefix for that country. It can also be used for the reverse search, i.e. by entering the international dialling code you are able to find out in which country a telephone number is located.

  • Enter a country name to return an international dialling code.
  • Enter an international dialling code to return the country name for that code.

Please see the Documentation for more information including a list of mandatory and optional parameters, and returned values.

API method to use: country_dial
|
Credits per use: 0.01

Returns international dialling codes for a given country, and vice versa.

This service is essential for any organisation that has a need to make overseas calls. The correct international dialling code must prefix the telephone number in order to connect to that country.

The international dialling code for the UK is +44, therefore the usual format for dialling our offices in the UK from abroad would be +44 (0)1904 217765.

Try the service out with our online demo.

Mandatory Parameters


Name Description
api_key or javascript_key Use your API key if invoking server-side. If invoking from the browser via JavaScript, generate a JavaScript key using the javascript_key method.
text Enter a country name or dialling code.

Optional Parameters


Name Description
client You can optionally include an identifier for your final client or user. This is logged in your usage log and you will be able to view your usage statistics by client.
output Set to json for a JSON response; the default response is XML. Not applicable to the SOAP API.
callback When using JSON, specify a JSONP wrapper in which the JSON response is to be wrapped.

Returned Values


The XML response is contained within a <country_dial_res> element.

Name Description
status Returns ok if the operation has succeeded, or error if an error has occurred; Returns the error_code for error details.
error_code Returns the error code when the status is error. See below for error codes.
t2a_version_number The current API version number.
credit_used The number of credits used in order to execute the request.
mode Returns normal or test when executed in the free test mode.
country_dial_list An array of country_dial records.

Response Structure <country_dial>


This structure is only used by this method.

Element Description
code The international dialling code.
name The country name.

Error Codes


Name

Description

missing_text

Mandatory parameter

See the common error codes.

Free Test Mode


When operating in the free test mode errors are returned if mandatory parameters are missing, or it returns a dummy data response, in an identical format to a real response.

Note that the mode is returned as test when the method is operating in the free test mode.

Example XML Response


This is an actual response for the text value united:-


<?xml version="1.0"?>
<country_dial_res>
  <country_dial_list>
    <t2a_version_number>1.0.0</t2a_version_number>
    <status>ok</status>
    <country_dial>
      <name>United Arab Emirates</name>
      <code>971</code>
    </country_dial>
    <country_dial>
      <name>United Kingdom</name>
      <code>44</code>
    </country_dial>
    <country_dial>
      <name>United States of America</name>
      <code>1</code>
    </country_dial>
  </country_dial_list>
</country_dial_res>

There are two ways to authenticate your application with the T2A API. The two implementation examples on this page cover each type of authentication

We recommend using an API key for internal applications and the javascript key for public facing applications where you would want to protect your API key.

Please note: The examples below run on a sandbox environment which return sample data. To quality check the data we provide, up to 3 free searches are available in the demo tab with results showing live [REDACTED] data.

API key


<div class="country-dial-example">
  <form class="country-dial-form">

    <div class="form-group">
          <label for="surname">International dialling code or country name</label>
          <input type="text" class="form-control" id="text" placeholder="e.g. United Kingdom or +44">
      </div>

    <button type="submit" class="btn example-submit">Submit</button>
  </form>
</div>

<div class="results">
  <div id="results-output"></div>
  <a class="results-return" href="#">Back to search</a>
</div>
                
.country-dial-example, .results {
  margin: 20px auto;
  width: 400px;
}

form.country-dial-form, .results {
    background-color: #F6F6F6;
    border: 1px solid #CBCBCB;
    padding: 15px;
}

.example-submit {
    background-color: #F0614C;
    border-radius: 2px;
    font-size: 11px;
    font-weight: 400;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.193em;
    width: 138px;
    height: 41px;
    margin-top: 10px;
}

.results {
  display: none;
}

.results-return {
    font-weight: 600;
    color: #F0614C;
}

#results-output span {
    font-weight: bold;
    text-transform: capitalize;
}

#results-output hr {
    border-top: 1px solid #000;
}

.error {
  font-size: 11px;
  color: #f00;
}
                
$(document).ready(function(){ 	
    $(".country-dial-form").submit(function(e) {
        e.preventDefault();	

        $('.error', $(this)).remove();

        var text = $("#text");        if(!text.val()) {
                errorBefore("Please enter an international dialling code or country name.", text);
            }

        if($('.error', $(this)).length) {	
            $('.error', $(this)).first().next('input').focus();
        } else {
    
            $.ajax({
                url: 'https://api.t2a.io/rest/rest.aspx',
                dataType: 'json',
                data: {
                    'method'   : "country_dial",
                    'api_key'  : 'sandbox',
                    'text' : text.val(),
                    'output'   : 'json'
                    },
                success: function(result){
                    if(result.status == "error") {
                        $('#results-output').append('<p class="output"><strong>Error:</strong>' + result.error_code +'</p>');
                    } else {
                        var i = 0;
                        if(typeof result.country_dial_list !== "undefined") {
                            result.country_dial_list.forEach(function(country_dial_list_item){
                                if(i>0){
                                    $('#results-output').append('<hr>');
                                }
                                var exceptionsArray = ['META', 'created_details', 'years_list', 'address_key', 'organisation_key', 'dob_details'];
                                    
                                for (var key in country_dial_list_item) {
                                    if(!key.includes('id') && !exceptionsArray.includes(key) ) {
                                        var keyName = key.replace('_', ' ');
                                        $('#results-output').append('<p class="output"><span>' + keyName + ':</span> ' + country_dial_list_item[key] + '</p>');
                                    }
                                }
                                i++;
                            });
                        }
                    }
                    $('.country-dial-example').hide();
                    $('.results').show(); 
               }
            });
        }
    });
    
    $('.results-return').on('click', function(e){
        e.preventDefault();
        $('#results-output').empty();
        
        $('.country-dial-example').show();
        $('.results').hide();
    });
});

function errorBefore(msg, insertBefore) {
    $('<p class="error">' + msg + '</p>').insertBefore(insertBefore);
}

Javascript key


<div class="country-dial-example">
  <form class="country-dial-form">

    <div class="form-group">
          <label for="surname">International dialling code or country name</label>
          <input type="text" class="form-control" id="text" placeholder="e.g. United Kingdom or +44">
      </div>

    <button type="submit" class="btn example-submit">Submit</button>
  </form>
</div>

<div class="results">
  <div id="results-output"></div>
  <a class="results-return" href="#">Back to search</a>
</div>
                
.country-dial-example, .results {
  margin: 20px auto;
  width: 400px;
}

form.country-dial-form, .results {
    background-color: #F6F6F6;
    border: 1px solid #CBCBCB;
    padding: 15px;
}

.example-submit {
    background-color: #F0614C;
    border-radius: 2px;
    font-size: 11px;
    font-weight: 400;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.193em;
    width: 138px;
    height: 41px;
    margin-top: 10px;
}

.results {
  display: none;
}

.results-return {
    font-weight: 600;
    color: #F0614C;
}

#results-output span {
    font-weight: bold;
    text-transform: capitalize;
}

#results-output hr {
    border-top: 1px solid #000;
}

.error {
  font-size: 11px;
  color: #f00;
}
                
$(document).ready(function(){ 	
    $(".country-dial-form").submit(function(e) {
        e.preventDefault();	

        $('.error', $(this)).remove();

        var text = $("#text");        if(!text.val()) {
                errorBefore("Please enter an international dialling code or country name.", text);
            }

        if($('.error', $(this)).length) {	
            $('.error', $(this)).first().next('input').focus();
        } else {
            $.ajax({
                url: 'https://t2a.io/ajax/getExampleJSKey',
                dataType: 'json',
                success: function (result) {       
                        
                    if (result.status)
                    {       
                        $.ajax({
                            url: 'https://api.t2a.io/rest/rest.aspx',
                            dataType: 'json',
                            data: {
                                'method'   : "country_dial",
                                'javascript_key'  : result.javascript_key,
                                'domain' : "t2a.io", 
                                'text' : text.val(),
                                'output'   : 'json'
                            },
                            success: function(result){
                        if(result.status == "error") {
                            $('#results-output').append('<p class="output"><strong>Error:</strong>' + result.error_code +'</p>');
                        } else {
                            var i = 0;
                            if(typeof result.country_dial_list !== "undefined") {
                                result.country_dial_list.forEach(function(country_dial_list_item){
                                    if(i>0){
                                        $('#results-output').append('<hr>');
                                    }
                                    
                                    var exceptionsArray = ['META', 'created_details', 'years_list', 'address_key', 'organisation_key', 'dob_details'];
                                    
                                    for (var key in country_dial_list_item) {
                                        if(!key.includes('id') && !exceptionsArray.includes(key) ) {
                                            var keyName = key.replace('_', ' ');
                                            $('#results-output').append('<p class="output"><span>' + keyName + ':</span> ' + country_dial_list_item[key] + '</p>');
                                        }
                                    }
                                    i++;
                                });
                            }
                       }
                                $('.country-dial-example').hide();
                                $('.results').show(); 
                            }
                        });
                    }
                }
            });
        }
    });
    
    $('.results-return').on('click', function(e){
        e.preventDefault();
        $('#results-output').empty();
        
        $('.country-dial-example').show();
        $('.results').hide();
    });
});

function errorBefore(msg, insertBefore) {
    $('<p class="error">' + msg + '</p>').insertBefore(insertBefore);
}

This example first needs to call to a file on your server, which will provide the user with an API key from your javascript key.

In our example above we have used a PHP file located at ajax/getExampleJSKey which looks like the example below

    <?php

        $url = 'https://api.t2a.io/rest/rest.aspx'
            . "?method=javascript_key"
            . "&api_key=sandbox" .
            . "&domain=" . $_SERVER['HTTP_HOST'];
            . '&ip_address=' . get_user_ip()
            . "&lifetime_minutes=10";

        $result = simplexml_load_file($url);

        if ($result->javascript_key) {
            echo (string)$result->javascript_key;
        }

API Endpoint & Authentication

Demo

Enter either an international dialling code or a country name.

Price calculator

Price Calculator

Number of checks: 50 Price per check: 50p