Have you got a UK postcode or lat/long and need to know the more information about the location? Postcodes.io may be the site for you. Featuring simple API example.

Thanks to Andre de Vries for using this in one of his demonstrations.

Let’s jump right in and show what you can get out of this API.

URL

You can can a URL like below to get information about the postcode:

Response

And this is the kind of response you will get:

“postcode”: “BS6 7NP”,
“quality”: 1,
eastings“: 357567,
northings“: 175620,
country“: “England”,
nhs_ha“: “South West”,
longitude“: -2.612395,
latitude“: 51.477937,
european_electoral_region“: “South West”,
primary_care_trust“: “Bristol”,
region“: “South West”,
lsoa“: “Bristol 017B”,
msoa“: “Bristol 017”,
“incode”: “7NP”,
“outcode”: “BS6”,
parliamentary_constituency“: “Bristol North West”,
admin_district“: “Bristol, City of”,
parish“: “Bristol, City of, unparished area”,
“admin_county”: null,
admin_ward“: “Westbury-on-Trym and Henleaze”,
“ced”: null,
“ccg”: “NHS Bristol, North Somerset and South Gloucestershire”,
“nuts”: “Bristol, City of”,
codes“: {
“admin_district”: “E06000023”,
“admin_county”: “E99999999”,
“admin_ward”: “E05010917”,
“parish”: “E43000019”,
“parliamentary_constituency”: “E14000600”,
“ccg”: “E38000222”,
“ccg_id”: “15C”,
“ced”: “E99999999”,
“nuts”: “UKK11”

See more ways to use the API here

I’m new to APIs – what is this?

APIs are something that you can use to interact with supported web services through using URLs. In this example I used the url: api.postcodes.io/postcodes/bs67np and received the response above.

There are many ways to interact with an API, one of which being with Alteryx. With just a single tool you can send the URL and receive the response with your information and this can be built into larger workflows to make use of the service. Here’s how you can use it

How you can use it

1. Create the URL

You can use the text input tool to create a record with the URL that you can to use.

2. Download tool

Now add in a download tool

Configure the download tool by telling it which column to use as a URL. (just a note here that using APIs can mean that the configuration of the download tool is more complex).

3. Hit run

You should now have two new fields, created by the download tool, with the headers of DownloadData and DownloadHeaders. The headers contains information about your connection to the API and server behind it and the data contains the data.

Why is my data in this weird format?

If you look into the headers you should be able to see the file type of the response that you got. In this case, we are being returned with data in a json format.

Content-Type: application/json;

Fortunately, Alteryx has a tool that allows you to change the data into one more friendly for the program. This tool is called ‘JSON Parse’ and you can put it after your download tool.

(don’t forget to select ‘DownloadData’ as your JSON field in the configuration of the tool!)

Conclusion

postcodes.io/ is an API that seems very useful in finding out UK geographic information with just a postcode or lat/long and you can access this data with just a couple tools in Alteryx.