Posted on Leave a comment

Addressian for Woocommerce WordPress Plugin

TL;DR
We have finally released our Woocommerce plugin. You can install/download it from the WordPress plugins page.

 

It’s finally here! We have been working hard to create a plugin so our customers could easily integrate their WordPress/Woocommerce shops with Addressian. Nothing explains how something works better than some images:

Address Finder by Postcode mode:

 

 

Address Autocomplete mode:

 

 

If you are still interested, head over to your Plugins’ page in WordPress backend, and search for “Addressian for Woocommerce”. You are guaranteed to be up and running in a few minutes!

 

 

Posted on Leave a comment

How to create a basic postcode lookup or address finder field using easy-autocomplete

There are many ways you could make a REST call to our services and there are tons of libraries in many languages that facilitate this.

On the home page of Addressian, there is a demo section that implements “search-as-you-type”. Here is how that is implemented:

Search-as-you-type

We use a Javascript library called easy-autocomplete.

Add the dependencies to your HTML page’s header section:

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/jquery.easy-autocomplete.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/easy-autocomplete.min.css">

Then create a section in your HTML form with an “input” element inside it:

<section class="easy-autocomplete">
 <div>
  <input id="tags" type="text" autocomplete="off" placeholder="Search...">
 </div>
 </section>

Then add this bit of Javascript, anywhere in your HTML source code:

<script>
  $(function() {
   var selectItem = function(event, ui) {
    $("#tags").val(ui.item.value);
    return false;
   }
   var options = {
    url: function(phrase) {
     return "https://api-full.addressian.co.uk/address/" + phrase;
    },
    ajaxSettings: {
     headers: {
      'x-api-key': '[your_api_key]'
     }
    },
    getValue: function(element) {
     return element.address.join(", ") + ", " + element.citytown + ", " + element.postcode;
    },
    theme: "blue-light",
    placeholder: "Type an address in here..",
    list: {
     maxNumberOfElements: 20,
     onClickEvent: function() {
      alert("The postcode of the item you clicked on was " + $("#tags").getSelectedItemData().postcode);
     }
    }

   };
   $("#tags").easyAutocomplete(options);
  });
 </script>

Retrieve addresses from a postcode

Add the dependency to your HTML page’s header section:

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

Then create a section in your HTML form with an “input” element inside it:

<section class="easy-autocomplete">
  <input id="postcode" type="text" autocomplete="off" placeholder="search...">
  <button id="postcode-go">Go</button>
  <select id="postcode-dropdown" hidden=""></select>
 </section>

Then add this bit of Javascript, anywhere in your HTML source code:

<script>
  jQuery("#postcode-go").click(function() {

   if (jQuery("#postcode").val() == '') {
    return;
   }
   let dropdown = jQuery('#postcode-dropdown');
   dropdown.empty();
   dropdown.show()
   dropdown.append('<option selected="true" disabled>Choose your address</option>');
   dropdown.prop('selectedIndex', 0);
   dropdown.change(function() {

    var selectedAddress = JSON.parse($(this).children("option:selected").val());
    alert("The selected address is: " + selectedAddress.address + " And city is: " + selectedAddress.citytown);
   });
   const url = '';
   jQuery.ajax({
    beforeSend: function(request) {
     request.setRequestHeader("x-api-key", '[your_api_key]');
    },
    dataType: "json",
    url: "https://api-full.addressian.co.uk/address/" + jQuery("#postcode").val(),
    success: function(data) {
     jQuery.each(data, function(key, entry) {
      dropdown.append(jQuery('<option></option>').attr('value', JSON.stringify(entry)).text(entry.address.join(', ')));
     })
    }
   });
   jQuery.getJSON("", function(data) {});
  });
 </script>

Posted on Leave a comment

How to make a basic REST call in 8 different languages

To get you started, here are some examples for making a basic REST HTTP call, in 12 languages:

Java

OkHttp
   OkHttpClient client = new OkHttpClient();
   Request request = new Request.Builder()
     .url(“https://api-trial.addressian.co.uk/address/[your_address]”)
     .get()
     .addHeader(“x-api-key”, “[your_api_key]”)
   .build();
   Response response = client.newCall(request).execute();

Unirest
   HttpResponse<String> response = Unirest.get(“https://api-trial.addressian.co.uk/address/[your_address]”)
     .header(“x-api-key”, “[your_api_key]”)
     .asString();

cURL

   curl –request GET \
     –url ‘https://api-trial.addressian.co.uk/address/[your_address]’ \
     –header ‘x-api-key: [your_api_key]’

Wget

   wget –quiet \
     –method GET \
     –header ‘x-api-key: [your_api_key]’ \
     –output-document \
     – ‘https://api-trial.addressian.co.uk/address/[your_address]’

Javascript

   XMLHttpRequest
   var data = null;

   var xhr = new XMLHttpRequest();
   xhr.withCredentials = true;

   xhr.addEventListener(“readystatechange”, function () {
     if (this.readyState === this.DONE) {
       console.log(this.responseText);
     }
   });

   xhr.open(“GET”, “https://api-trial.addressian.co.uk/address/[your_address]”);
   xhr.setRequestHeader(“x-api-key”, “[your_api_key]”);

   xhr.send(data);

jQuery
   var settings = {
     “async”: true,
     “crossDomain”: true,
     “url”: “https://api-trial.addressian.co.uk/address/[your_address]”,
     “method”: “GET”,
     “headers”: {
     “x-api-key”: “[your_api_key]”
     }
   }

   $.ajax(settings).done(function (response) {
     console.log(response);
   });

PHP

ext-curl
   <?php

      $curl = curl_init();

        curl_setopt_array($curl, array(
        CURLOPT_URL => “https://api-trial.addressian.co.uk/address/[your_address]”,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => “”,
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => “GET”,
        CURLOPT_HTTPHEADER => array(
        “x-api-key: [your_api_key]”
        ),
      ));

      $response = curl_exec($curl);
     $err = curl_error($curl);

     curl_close($curl);

      if ($err) {
         echo “cURL Error #:” . $err;
      } else {
         echo $response;
   }

pecl/http v2

   <?php

     $client = new http\Client;
     $request = new http\Client\Request;

     $request->setRequestUrl(‘https://api-trial.addressian.co.uk/address/[your_address]’);
     $request->setRequestMethod(‘GET’);
     $request->setHeaders(array(
        ‘x-api-key’ => ‘[your_api_key]
     ));

     $client->enqueue($request)->send();
     $response = $client->getResponse();

     echo $response->getBody();

C#

   var client = new RestClient(“https://api-trial.addressian.co.uk/address/[your_address]”);
   var request = new RestRequest(Method.GET);
   request.AddHeader(“x-api-key”,[your_api_key]“);
   IRestResponse response = client.Execute(request);

Python 3

   import http.client

   conn = http.client.HTTPSConnection(“api-trial.addressian.co.uk”)
   headers = { ‘x-api-key’: “[your_api_key]” }
   conn.request(“GET”, “/address/[your_address]”, headers=headers)
   res = conn.getresponse()
   data = res.read()

   print(data.decode(“utf-8”))

Node

   var http = require(“https”);

   var options = {
      “method”: “GET”,
      “hostname”: “api-trial.addressian.co.uk”,
      “port”: null,
      “path”: “/address/[your_address]”,
      “headers”: {
         “x-api-key”: “[your_api_key]”
      }
   };

   var req = http.request(options, function (res) {
   var chunks = [];

   res.on(“data”, function (chunk) {
      chunks.push(chunk);
   });

   res.on(“end”, function () {
      var body = Buffer.concat(chunks);
      console.log(body.toString());
      });
   });

   req.end();

Posted on Leave a comment

What is a UK postcode made up of?

A Postcode is made up of the following elements:

PO1 3AX

PO the area. There are 124 postcode areas in the UK
1 the district. There are approximately 20 Postcode districts in an area
3 the sector. There are approximately 3000 addresses in a sector.
AX the Unit. There are approximately 15 addresses per unit.

The following list shows all valid Postcode formats. “A” indicates an alphabetic character and “N” indicates a numeric character.

Format Example
AN NAA M1 1AA
ANN NAA M60 1NW
AAN NAA CR2 6XH
AANN NAA DN55 1PT
ANA NAA W1A 1HQ
AANA NAA EC1A 1BB

Please note the following:

  • The letters Q, V and X are not used in the first position
  • The letters I,J and Z are not used in the second position.
  • The only letters to appear in the third position are A, B, C, D, E, F, G, H, J, K, S, T, U and W.
  • The second half of the postcode is always consistent numeric, alpha, alpha format and the letters C, I, K, M, O and V are never used.

Elements of a Postcode
The first part of the Postcode eg PO1 is called the outward code as it identifies the town or district to which the letter is to be sent for further sorting.

The second part of the postcode eg 1EB is called the inward code. This identifies the particular sector in the town or district to which the letter has been delivered and a thoroughfare, part of a thoroughfare or an individual address within that sector. The maximum number of delivery points covered by one postcode is 100 and the average is 15.

Postcode Area – this is the largest geographical unit of the postcode. Each one comprises one or two alpha
characters generally chosen to be a mnemonic of the area eg MK for Milton Keynes, SO for Southampton. There are currently 124 Postcode areas including Guernsey (GY) Jersey (JE) and the Isle of Man (IM)
Postcode District – Each postcode area is divided into a number of districts which are represented by the numerical portion of each part of the postcode. These numbers range from 0 to 99 eg MK42. In London a further alpha character is used to divide some districts into sub divisions eg EC1A.
Postcode sectors – Sectors are numbered 1,2,3,4,5,6,7,8,9,0. It should be noted that when sorting postcodes into
order, sector 0 is the tenth sector rather than the first.

(These conventions may change if operationally required.)

Posted on Leave a comment

Address lookup with postcode OR Search as user types

Typically, there are two common types of address lookup used on the internet: 

  1. User enters a postcode, presses a button, and the website retrieves a list of addresses associated with that postcode. The user chooses one of them, and the web form fills the form automatically.
  2. The user enters their postcode, along with a house/flat number and presses Search. The service then finds the best match(es) for that search and shows the user a list to choose from. The user picks one and the website automatically fills the form

Our service works in a similar fashion, with a few improvements:

  • Addressian automatically determines if the user has entered a postcode to get a list to choose from, or just typing their address naturally e.g. “45a sealey drive”. As a developer you would only use one API for both.
  • Our servers are fast. We user Amazon AWS servers and continually add resources to them, or buy more servers, and we do this proportionally to the number of customers and their volume.
  • Our prices are unbeatable! We give you 20,000 api calls a month, so you don’t have to worry about your quota. Use it to implement a search-as-you-type address finder in your online forms, and benefit from an improved conversion rate when customers are able to find their address with only a few characters. There are very few websites who actually offer this type of address entering.

We are extremely fast in searching 32 million UK addresses. We are even extremely faster when you just want to retrieve a list of addresses from a postcode.

Give Addressian a go. The free trial (activated in only 5 minutes) is more than enough to have a play around and use it to integrate an address finding system with your website forms.