Looking at the company in Figure \@ref(fig:chapi), we wouldn't know if the supplied postcode existed or not, given the base information supplied in the API. So we wrap the Companies House API within another API, which examines the supplied postcode and returns an assessment, as seen in Figure \@ref(fig:chapi2) below:
knitr::include_graphics("./images/chapi2.jpg")
The resource we use to determine whether or not the postcode exists is:
https://postcodes.io/
This is a free, open source postcode and geolocation API based on Open Data from the Office for National Statistics and Ordnance Survey. The endpoints and methods are listed on their site, but the one we use is Validate a postcode, and can be found here:
https://api.postcodes.io/postcodes/:postcode/validate
...where :postcode is replaced by the postcode we're looking to validate. For example in the company being assessed in example \@ref(fig:chapi), we used the following URL:
https://api.postcodes.io/postcodes/SE258BB/validate
...and the returned result is:
{status:200, result:false}
This is confirmed using Royal Mail's postcode address finder:
knitr::include_graphics("./images/rm1.jpg")
Now all we have to do is extract the company's postcode in Python, supply that to postcodes.io API and return the result, as seen in example \@ref(fig:chapi2).
Our API for doing this can be found here:
https://darlabs.herokuapp.com/v1/11659363/quality?pid=1
You can substitute any company number in the above URL to find out if that company's postcode exists.
As with any third party API, we don't know exactly where they get their data from. It's probably not coming from the Royal Mail Postcode Address File (PAF), but it seems to be very accurate. I've not yet found an address that is reported incorrectly using this API, but that's not to say it's 100% accurate. Use with caution.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.