Pezholio

15 Mar, 2010

Postcode to councillor in one easy step!

Posted by: Pez In: Open Data|stuff

Finding out who your councillor is isn’t always easy is it? Even if you know which council provides your services, wards often have odd sounding names, and council websites don’t always have an easy postcode search. With this in mind, and now the Office of National Statistics have released a brand new API and because I’ve got a day off looking after my new puppy, I decided to have a play and see if I could make it easier.

First I trawled through the documentation to find the best API methods for my needs, it turns out that this URL did what I needed:

http://neighbourhood.statistics.gov.uk/NDE2/Disco/SearchSByAByPostcode?LevelTypeId=14&Postcode={POSTCODE}

This basically asks the NeSS Data Exchange to return the details of a ward (which in Office of National Statistics language is level type ID 14) which a particular postcode is in. Helpfully, I don’t get the SNAC ID straight away (you’ll see why I need this later), so I have to get the ONS internal ID, and make another API call:

http://neighbourhood.statistics.gov.uk/NDE2/Disco/GetAreaDetail?AreaId={AREA ID}

This gives a whole bunch of extra info about the area, including the SNAC ID (which is called the ExtCode). Once I have that, I can then move across to OpenlyLocal, where I can get the councillor’s information:

http://openlylocal.com/wards/snac_id/SNAC ID.xml

Once I’ve got this info, I can then display it all, like so! Obviously if the council isn’t on OpenlyLocal, then we can’t show their details, but we can say who their council is and what ward they’re in, and then, with a bit more jiggery pokery on the OpenlyLocal side, we can direct them to their local authority’s website, like so!

Give it a try yourself, and let me know any feedback in the ol’ comments below. Obviously, this only shows your district council if you’re in a two tier council, but I’m working on getting county council info later :)

Oooh, it’s worth pointing out that you need a PSI click-use licence to publish the Data Exchange data on your own website, but it’s a doddle to apply for and goes live instantly!

Update: I’ve published the code on Github in case you want to see how I did it!

5 Responses to "Postcode to councillor in one easy step!"

1 | Dominic Burford

March 16th, 2010 at 8:09 am

Avatar

This is great, makes the job of performing postcode searches so much easier.

2 | Andrew Beeken

March 16th, 2010 at 9:18 am

Avatar

As more and more services like this are introduced I think it’s getting harder and harder for councils to find an excuse NOT to implement a MyArea style service. Using this kind of API only requires the most rudimentary of server side technology and its implementation is simple to say the least. Well done that man!

3 | Ade

April 8th, 2010 at 9:45 am

Avatar

I must admit that as I hit the ‘Submit’ button, I closed my eyes- experience has taught me these things don’t always do what they say on the tin. However, I was pleasantly surprised. It worked and returned just the right amount of information. Very impressed.

@Pezholio, as someone who is daily involved in local government, what are the technical objections a council might have to incorporating something like this on their site?

4 | Pez

April 8th, 2010 at 9:59 am

Avatar

I can’t see what the objections would be to be honest, we use the exact same method on the My Area page of the Lichfield District Council website.

With the release of CodePoint Open by Ordnance Survey last week, it’s actually easier to use that, rather than the NESS Data Exchange (which is really designed for far more high level things) – as well as the geographical data, it also gives you the snac IDs, split into county, district and ward levels. If you’d rather not download the whole dataset, I’ve helpfully packaged it as a web service at http://www.uk-postcodes.com (will blog about it later actually!)

5 | Pezholio » Blog Archive » The postcode – freed!

April 8th, 2010 at 10:35 am

Avatar

[...] matches postcodes to local authority information, something which, in the past, I’ve used the NESS Data Exchange for, but I’ll probably migrate to this, ‘cos it’s [...]

Comment Form