MapIt API Documentation

The documentation below is for developers who want to use MapIt as a web service, describing its REST API. If that’s all Greek to you, please see our page for non-developers.


MapIt API

General information

Format

All calls return JSON, and you can generally get an HTML representation by adding .html on the end.

To use your API key, include it in each API call as either an api_key URL query parameter, e.g. https://mapit.mysociety.org/area/2244?api_key=KEY, or an X-Api-Key HTTP request header. All API responses include your current usage and limit in the X-Quota-Current and X-Quota-Limit response headers.

Whenever an area is returned from MapIt, it is as a dictionary with the following keys: id, name, country, type, parent_area, generation_low, generation_high, codes.

Historical areas
By default, calls will return active areas; for some calls you may specify a previous generation to look up instead.
Technical queries
If you have any technical queries with the API, please contact us.

lookup quota

URL:
/quota
Returns:

Your current quota usage and limit. Note: Accessing this endpoint does not count against your limit.

lookup by postcode

URL:
/postcode/[postcode]
Returns:

Information on a particular postcode, including its centroid location in WGS84 latitude/longitude, and the areas that is contained within.

Optional query parameters:
  • generation, to return results from a previous generation.
  • min_generation, to return results since that generation.
Shortcuts:

As well as the areas hash of all areas, the results include a shortcuts key that provides a quick lookup of council, ward, and WMC IDs. If the area is two-tier, the council and ward values will be objects with keys of county and district.

Example:

If your postcode was SW1A 1AA you would load /postcode/SW1A1AA

By default the response is in JSON, if you want a human readable page then append ‘.html’ to the url /postcode/SW1A1AA.html

lookup by partial postcode

URL:
/postcode/partial/[partial postcode]
Returns:

Geographical details for the centroid of the partial postcode specified.

Example:

lookup by point

URL:
  • /point/[SRID]/[x],[y]
  • /point/[SRID]/[x],[y]/box
Parameters:

SRID is a unique number referring to a particular co-ordinate system; the ones you probably are interested in are 27700 for British National Grid, 4326 for WGS84 lon/lat, and 29902 for the Irish National Grid.

x and y are the co-ordinates of the point in the co-ordinate system; note that x,y means longitude,latitude.

Optional query parameters:
  • type, to restrict results to a particular area type or types (multiple types separated by commas);
  • generation, to return results for a previous generation.
  • min_generation, to return results since that generation.
  • country, to restrict results to areas with particular country codes (multiple country codes separated by commas).
  • within, to show results within the specified distance (up to 10000 metres) of the point, not just the point itself (not /box).
Returns:

A hash of the areas that the point is contained within. If the /box version is used, only the area bounding boxes are considered.

Example:
Example of areas containing (400000,300000).

lookupnearest postcode

URL:
/nearest/[SRID]/[x],[y]
Parameters:
Same as for by point.
Returns:
The postcode closest to the particular point.
Example
Example of postcode nearest to (400000,300000).

lookup by area

URL:
  • /area/[area ID or ONS code]
  • /area/[area ID]/example_postcode
  • /area/[area ID]/geometry
  • /area/[area ID].[kml or geojson or wkt]
  • /area/[SRID]/[area ID].[kml or json or wkt]
Optional query parameters:
simplify_tolerance, a floating point parameter to simplify the polygons returned.
Returns:
Information on a particular area, including name, type, parent, and any associated codes (see below for details). The code lookups redirect to the area URI. example_postcode returns a random postcode within the area specified. geometry returns centroid, extent and area of the area.
Examples:

lookup multiple areas

URL:
  • /areas/[area IDs]
  • /areas/[area IDs]/geometry
  • /areas/[area IDs].[kml|geojson]
  • /areas/[type(s)]
  • /areas/[name prefix]
Parameters:
Separate multiple parameters with commas. Name prefix means it will return any area that starts with the string given. The current area types include: CTY (county council), CED (county ward), COI (Isles of Scilly), COP (Isles of Scilly parish), CPC (civil parish/community), CPW (civil parish/community ward), DIS (district council), DIW (district ward), ER (English region), GLA (London Assembly), LAC (London Assembly constituency), LBO (London borough), LBW (London ward), LGD (NI council), LGE (NI electoral area), LGW (NI ward), MTD (Metropolitan district), MTW (Metropolitan ward), NIE (NI Assembly constituency), OLF (Lower Layer Super Output Area, Full), OLG (Lower Layer Super Output Area, Generalised), OMF (Middle Layer Super Output Area, Full), OMG (Middle Layer Super Output Area, Generalised), SPC (Scottish Parliament constituency), SPE (Scottish Parliament region), TTW (Travel to Work Area), UTA (Unitary authority), UTE (Unitary authority electoral division), UTW (Unitary authority ward), WAC (Welsh Assembly constituency), WAE (Welsh Assembly region), WMC (UK Parliamentary constituency).
Optional query parameters:
  • generation, to return areas in that generation (type and name lookups only).
  • min_generation, to return areas since that generation (type and name lookups only).
  • type, to restrict results to a type or types (multiple separated by commas; name lookup only).
  • country, to restrict results to areas with particular country codes (multiple separated by commas; type and name lookups only).
Returns:

Information on multiple areas that match the parameters provided, as a dictionary indexed by area ID. The geometry argument lets you fetch multiple single area geometry results at once.

Examples:

lookup by code

URL:
  • /code/[code type]/[code]
Parameters:
code type and a code should uniquely identify an area. (MapIt uses code types and codes to associate external identifiers with areas.) The current code types are: ons (SNAC codes, which are old ONS codes), gss (new ONS codes), unit_id (OS admin area IDs from Boundary-Line) and osni_old (old OSNI object IDs)
Returns:

This returns an HTTP 302 Found redirect to the corresponding /area/[area ID] page. Any format extension (.html or .json) will be preserved in the URL that's redirected to.

Examples:

Generations

URL:
/generations
Returns:
A list of all generations in this installation of MapIt.
Note that only generations from 12 upwards actually exist, apart from some council names in generation 10 in order for FixMyStreet to show expired councils on its All Reports page.
Example
List of generations