Search For an Address or Postcode

Use our data to find a UK address from a postcode or vice versa


Our data is the most up-to-date source of address information you will find in the UK.

Having accurate up-to-date address and postcode data is vital for all CRM systems, and any websites and apps that require customers to create an account using their name and address.

You can use our data to facilitate the process of completing address details on customer signup/enquiry forms, making it quicker and easy for the customer, but also ensuring the information you receive is accurate, up-to-date and complete.

As a data cleansing tool our service can be used to ensure full and accurate data within CRM systems for marketing campaigns. Old addresses can be updated and incomplete addresses improved, that may be missing postcodes for example.

API method to use: address_search

How it works

We can identify a full and accurate address from a partial address and/or postcode. All you need to do is submit the information you have and or API method will complete and update.

The method returns a list of UK addresses and postcodes that match your search criteria, when the following data is supplied:

  • a partial address (when conducting a postcode search)
  • a postcode, plus optional Building name/number (when conducting an address search)

More details on mandatory and optional parameters, plus a list of returned values can be found in the Description section.

Next Steps…

We will give you a unique API key to allow you to test the method using credits on your T2A account. If you do not have an account you will first need to sign up.

 

Let's get started
API method to use: address_search
|
Credits per use: 1.7

Searches the UK postcodes data (PAF) to find a UK address from a postcode or vice versa.

This is the most up-to-date source of address information you can find in the UK.

We can identify a full and accurate address from a partial address and/or postcode - all you need to do is enter the information you have and we will complete and update it. We know how important it is to have accurate contact information for your customers so we want to make it as easy as possible for you to have a complete and accurate customer contact database.

Save valuable time and effort by adding this service to your CRM system, website or other business application. It can be used as a data cleansing tool or can facilitate the process of filling in address details on forms to ensure that the information provided is accurate.

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.

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.
postcode Enter a UK postcode; you may also enter a house number as the address parameter.
address If used with a postcode, this is an optional house number; if used alone, this is the address to be searched for.
records_per_page Specify the number of records to return on the current page. We offer page caching for this method - once your search is invoked, we store the pages on our server for 60 minutes; a subsequent request for a page of results from that search is displayed from the cache, at no charge to you. See result page caching.
page_num Zero based integer - current page number to return.

Returned Values


The XML response is contained within a <address_search_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.
address_list An array of address records.
total_records

The total number of records, irrespective of the number displayed on any page.

This is only used when a address_list is present.

page_number

Current page being displayed, a zero-based integer.

This is only used when a address_list is present.

Error Codes


See the common error codes. There are no errors which are specific to this method.

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



<?xml version="1.0" encoding="utf-8" ?>
<address_search_res>
  <t2a_version_number>1.0.0</t2a_version_number>
  <status>ok</status>
  <total_records>1</total_records>
  <page_number>0</page_number>
  <address_list>
    <address>
      <line_1>4 Imagination Gardens</line_1>
      <line_2>Magic Street</line_2>
      <line_3/>
      <place>Heslingdown</place>
      <town>York</town>
      <postcode>YO10 5NP</postcode>
      <addr_single_line>4 Imagination Gardens, Magic Street, Heslingdown, York, YO10 5NP</addr_single_line>
    </address>
  </address_list>
</address_search_res>

Example JSON Response


{
  "address_list":[
  {
    "line_1":"4 Imagination Gardens",
    "line_2":"Magic Street",
    "line_3":"",
    "place":"Heslingdown",
    "town":"York",
    "postcode":"YO10 5NP"
  }
  ],
  "t2a_version_number":"1.0.0",
  "status":"ok"
}


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.

Note: examples below show a restricted result set with a maximum of 3 results per search

API key


<div class="address-search-example">
  <form class="address-search-form">

    <div class="form-group">
          <label for="surname">Address</label>
          <input type="text" class="form-control" id="address" placeholder="Building name or number">
      </div>

    <div class="form-group">
          <label for="surname">Postcode</label>
          <input type="text" class="form-control" id="postcode" placeholder="Postcode">
      </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>
                
.address-search-example, .results {
  margin: 20px auto;
  width: 400px;
}

form.address-search-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(){ 	
    $(".address-search-form").submit(function(e) {
        e.preventDefault();	

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

        var address = $("#address");        var postcode = $("#postcode");        if($('.error', $(this)).length) {	
            $('.error', $(this)).first().next('input').focus();
        } else {
    
            $.ajax({
                url: 'https://api.t2a.io/rest/rest.aspx',
                dataType: 'json',
                data: {
                    'method'   : "address_search",
                    'api_key'  : 'ZmPdo8qZCBTAvwh7SQnEdjkd03t2_3pA95464vD2p7zY',
                    'address' : address.val(),
                    'postcode' : postcode.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.address_list !== "undefined") {
                            result.address_list.forEach(function(address_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 address_list_item) {
                                    if(!key.includes('id') && !exceptionsArray.includes(key) ) {
                                        var keyName = key.replace('_', ' ');
                                        $('#results-output').append('<p class="output"><span>' + keyName + ':</span> ' + address_list_item[key] + '</p>');
                                    }
                                }
                                i++;
                            });
                        }
                    }
                    $('.address-search-example').hide();
                    $('.results').show(); 
               }
            });
        }
    });
    
    $('.results-return').on('click', function(e){
        e.preventDefault();
        $('#results-output').empty();
        
        $('.address-search-example').show();
        $('.results').hide();
    });
});

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

Javascript key


<div class="address-search-example">
  <form class="address-search-form">

    <div class="form-group">
          <label for="surname">Address</label>
          <input type="text" class="form-control" id="address" placeholder="Building name or number">
      </div>

    <div class="form-group">
          <label for="surname">Postcode</label>
          <input type="text" class="form-control" id="postcode" placeholder="Postcode">
      </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>
                
.address-search-example, .results {
  margin: 20px auto;
  width: 400px;
}

form.address-search-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(){ 	
    $(".address-search-form").submit(function(e) {
        e.preventDefault();	

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

        var address = $("#address");        var postcode = $("#postcode");        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'   : "address_search",
                                'javascript_key'  : result.javascript_key,
                                'domain' : "t2a.io", 
                                'address' : address.val(),
                                'postcode' : postcode.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.address_list !== "undefined") {
                                result.address_list.forEach(function(address_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 address_list_item) {
                                        if(!key.includes('id') && !exceptionsArray.includes(key) ) {
                                            var keyName = key.replace('_', ' ');
                                            $('#results-output').append('<p class="output"><span>' + keyName + ':</span> ' + address_list_item[key] + '</p>');
                                        }
                                    }
                                    i++;
                                });
                            }
                       }
                                $('.address-search-example').hide();
                                $('.results').show(); 
                            }
                        });
                    }
                }
            });
        }
    });
    
    $('.results-return').on('click', function(e){
        e.preventDefault();
        $('#results-output').empty();
        
        $('.address-search-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=ZmPdo8qZCBTAvwh7SQnEdjkd03t2_3pA95464vD2p7zY" .
            . "&domain=" . $_SERVER['HTTP_HOST'];
            . '&ip_address=' . $_SERVER['REMOTE_ADDR']
            . "&lifetime_minutes=10";

        $result = simplexml_load_file($url);

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