Integration with UK’s postcodeanywhere


While working on Loan Script project of one of our UK client, we used data from postcodeanywhere to validate various customer data. The purpose of the project was to provide instant loan approval (or disapproval) to the customer. In conjunction with Equifax and our own custom rules – Walking Tree has ensured that right customer is able to take hassle free loan and at the same time, the customer with incorrect information or bad credit are evaluated against desired criteria to ensure that business is not at risk.

Postcodeanywhere team has provided various ways to use their data. One of the way is to use their web services to get the address details of the customer. For using their web services we have to get the license from the PostcodeAnywhere website. It will provide a account code and license for the consumers to utilise their services.

Whenever  any request made to the PostcodeAnywhere, we have to send credential information (the account code and license code) with house number and postcode details. Request should be sent to the urlhttp://services.postcodeanywhere.co.uk/xml.aspx?&action=lookup&type=by_postcode&building=***&postcode=***&account_code=***&license_code=***” with the data, later the response will be captured by using the file_get_contents() and simplexml_load_string() functions.

  • file_get_contents which is used to read the response file as a string.
  • simplexml_load_string which is used to read the string of xml as an object.

Based on the house number or name and postcode this web service will provide an unique id to fetch the address. For fetching the customer address we have to use the url http://services.postcodeanywhere.co.uk/xml.aspx?&action=fetch&id=***&language=enLanguageEnglish&style=rawgeographic&account_code=***&license_code=*** “. By using the above functions we will get the address details of the customer.

The following code will help you to get the address details of a customer from the Web services.

function pcaByPostcodeFiltered(){

$building = $_REQUEST[“building”];

$postcode= $_REQUEST[“postcode”];

$account_code= $_REQUEST[“account_code”];

$license_code= $_REQUEST[“license_code”];

$machine_id = $_REQUEST[“machine_id”];

//Built with help from James at http://www.omlet.co.uk/

//Build the url

$url = “http://services.postcodeanywhere.co.uk/xml.aspx?”;

$url .= “&action=lookup”;

$url .= “&type=by_postcode”;

$url .= “&building=” . urlencode($building);

$url .= “&postcode=” . urlencode($postcode);

$url .= “&account_code=” . urlencode($account_code);

$url .= “&license_code=” . urlencode($license_code);

$url .= “&machine_id=” . urlencode($machine_id);

//Make the request

$data = simplexml_load_string(@file_get_contents($url));

//Check for an error

if ($data->Schema[‘Items’]==2){

throw new exception ($data->Data->Item[‘message’]);

}

//Create the response

foreach ($data->Data->children() as $row){

$rowItems=””;

foreach($row->attributes() as $key => $value){

$rowItems[$key]=strval($value);

}

$output[] = $rowItems;

}

$detailAddress = pcaFetchAddress(

$output[0][“id”] ,

“enLanguageEnglish” ,

“rawgeographic”,

$account_code,

$license_code,

$machine_id,

“”

);

echo json_encode($detailAddress);

}

function pcaFetchAddress($id, $language, $style, $account_code, $license_code, $machine_id, $options){

//Build the url

$url = “http://services.postcodeanywhere.co.uk/xml.aspx?”;

$url .= “&action=fetch”;

$url .= “&id=” . urlencode($id);

$url .= “&language=” . urlencode($language);

$url .= “&style=” . urlencode($style);

$url .= “&account_code=” . urlencode($account_code);

$url .= “&license_code=” . urlencode($license_code);

$url .= “&machine_id=” . urlencode($machine_id);

$url .= “&options=” . urlencode($options);

//Make the request

$data = simplexml_load_string(@file_get_contents($url));

//Check for an error

if ($data->Schema[‘Items’]==2){

throw new exception ($data->Data->Item[‘message’]);

}

//Create the response

foreach ($data->Data->children() as $row){

$rowItems=””;

foreach($row->attributes() as $key => $value){

$rowItems[$key]=strval($value);

}

$output[] = $rowItems;

}

//Return the result

return $output;

}

After getting the response object from PostCodeAnyWhere, we have to show this data to the user in a form. If the data supplied for verification is incorrect at that time postcodeanywhere is unable to get the details of the customer and throws error message.

Working example :

Request :

action=pcaByPostcodeFiltered&building=4&postcode=BA13%203BN&account_code=RISKI11112&license_code=CR89-XJ31-HC77-JD88&machine_id=”

Response :

[{

“id”:”1237995.00″,”seq”:”0″,

“organisation_name”:”Dorothy House Cancer Shop”,                              “line1″:”41-43 High Street”,                                                 “post_town”:”Westbury”,”county”:”Wiltshire”,

“postcode”:”BA13 3BN”,                                                        “mailsort”:”70716″,”barcode”:”(BA133BN2P1)”,

“is_residential”:”0″,

“is_small_organisation”:”1″,

“is_large_organisation”:”0″,

“delivery_point_suffix”:”2P”,

“checksum”:”1″,”name_or_number”:”41-43″,                                “building_number”:”41-43″,                                                    “thoroughfare_name”:”High”,                                                   “thoroughfare_descriptor”:”Street”,

“number_of_households”:”1″,

“building_name_or_number”:”41-43″,                                            “reformatted_building_number”:”41-43″,                                        “grid_east_m”:”387233″,”grid_north_m”:”151303″,

“longitude”:”-2.1829879278687″,                                               “latitude”:”51.2602331059386″,

“os_reference”:”ST 87233 51303″,

“wgs84_longitude”:”-2.18437243732689″,                                        “wgs84_latitude”:”51.2606872073853″

}]

Based on this object we have to show details to the customer.

While above program gives you some idea about how to use PostCodeAnywhere, you may like to visit their Web Site to understand the complete list of features provided by them. They don’t only provide you with valid address, but they also help you in optimizing your customer’s UI interface, you can use their tools for Geocoding, store finding, maps & navigation, etc.

Also, they charge a nominal fee, which is much less as compared to Equifax. Overall, PostCodeAnywhere is a reliable information which you can use to ensure that you have cleansed customer information.

Walking Tree has recently implemented this for one of its customer in UK. We are also trying to partner with CRISIL in India to come up with similar solution which Equifax and PostCodeAnywhere combination is providing. If you need any professional services from WTC then you get our contact detail from Contact Us page on our company website.

Tagged with: , , , ,
Posted in General
3 comments on “Integration with UK’s postcodeanywhere
  1. Adam says:

    If the address data is your main interest – you might want to have a look at other resellers of the Royal Mail PAF. The data is all the same, but pricing can vary dramatically. Just google “postcode address lookup”

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

We Have Moved Our Blog!

We have moved our blog to our company site. Check out https://walkingtree.tech/index.php/blog for all latest blogs.

Sencha Select Partner Sencha Training Partner
Xamarin Authorized Partner
Recent Publication
%d bloggers like this: