The data that's submitted to this site is available as a CSV/Excel download and programmatically via a RESTful web service called PopIt, which stores information about people and their positions in organizations. (You can find out more about PopIt here.)
CSV/Excel Download
Download of the 2015 candidates
API
The base API URL for the data is:
http://yournextmp.popit.mysociety.org/api/v0.1/
You can read more generic documentation for the PopIt API or just follow the simple examples that follow.
Find a Constituency ID
In order to look up candidates for a constituency, you have to find the ID of that constituency. The IDs that we use for constituencies are the IDs for Westminster constituencies areas in another web service, MapIt.
... from a postcode
Suppose you want to find the constituency for the postcode SW1A 1AA, then you would make a GET request to the following URL:
http://mapit.mysociety.org/postcode/SW1A1AA
This returns a JSON object, wherein the constituency ID can be found at .shortcuts.WMC.
There's more documentation available on postcode lookups on the MapIt front-page.
... from a latitude / longitude or other coordinate
You can look up constituencies in MapIt using a variety of coordinate systems. To give the most common example, you might have a WGS84 coordinate from a GPS or location API, in which can you should put the SRID 4326 in your lookup. For example, latitude 52.205083 and longitude 0.115194 could be looked up with:
http://mapit.mysociety.org/point/4326/0.115194,52.205083?type=WMC(Note that the longitude comes before the latitude, which might not be what you expect.) The only key in that object is the constituency ID.
There's more documentation available on point lookups on the MapIt front-page.
... by selecting it from its name
If you need to produce a list of all constituencies (e.g. for a select box) and allow the user to pick one, you can get a list of all Westminster constituencies in the UK from this request:http://mapit.mysociety.org/areas/WMC
The returned data from that request has the constituency ID as its keys; the values are objects that include (among other things) a name element that gives you the official name of the constituency.
Find Candidates for a Constituency
There are broadly two ways you can approach getting candidate data for a constituency; one is slightly simpler, and just gives you the basic candidate and party information, while the second gives you the full data in Popolo format, which is more complex but useful if you're using tools that generically process Popolo data.
Simpler (Basic candidate information)
You can get all the candidates for a constituency, both in 2010 and 2015 by a query like:
http://yournextmp.popit.mysociety.org/api/v0.1/posts/CONSTITUENCY_ID?embed=membership.person
For example, for Dulwich and West Norwood, these would be the results.
If you iterate over the memberships in that result, each person will look something like:
"person_id": {
"id": "2009",
"birth_date": null,
"email": "....@example.org",
"gender": "female",
"name": "Tessa Jowell",
"party_memberships": {
"2010": {
"id": "party:53",
"name": "Labour Party"
}
},
"standing_in": {
"2010": {
"mapit_url": "http://mapit.mysociety.org/area/65808",
"name": "Dulwich and West Norwood",
"post_id": "65808"
},
"2015": null
},
(I've removed some fields there to keep the example simpler.) The two fields of particular interest are probably standing_in and party_memberships.
standing_in
This object will only have keys '2010' or '2015'. If one of these keys is present then we have known information about the candidate for the UK general election in that year. If the value is null then we know that they're not standing. If they are (or were) standing in the general election in that year then there will be a dictionary giving you details of the constituency they were standing in. So, in the example above we can see that Tessa Jowell stood in 2010 in Dulwich and West Norwood, but we know isn't standing in any consituency in 2015.
party_memberships
This object will similarly only have keys '2010' or '2015' and tells you what party the candidate is / was standing for in the general election of that year. So in the example above, you can see that Tessa Jowell stood for the Labour Party in 2010, but has no entry for 2015 (because, as the standing_in tells us) she's not standing in 2015.
More complex (Full Popolo information)
All the candidates we know about for a constituency can be returned by making a GET request to a URL of this form, where you should substitute in the constituency ID for CONSTITUENCY_ID:
http://yournextmp.popit.mysociety.org/api/v0.1/posts/CONSTITUENCY_ID?embed=membership.person.membership.organization
For example, for Dulwich and West Norwood, these would be the results. To explain further, that's showing information about the post "MP for Dulwich and West Norwood". Under the memberships key of the result dictionary you can find all memberships of this post - those that have the role "Candidate" were candidates at one point.
You should then look at the start and end dates of that membership, which will tell you whether they're a candidate for the 2015 election or were a past candidate for the 2010 election:
| Election | start_date | end_date |
| 2015 | 2010-05-07 | 9999-12-31 |
| 2010 | 2005-05-06 | 2010-05-06 |
Find a candidate by name
You can use the search/persons endpoint with a query paramter like q=name:"John Doe".http://yournextmp.popit.mysociety.org/api/v0.1/search/persons?q=name:%22FULL%20NAME%22
For example, you can find every David Jones in the database with this query. As above, the standing_in and party_memberships elements will give you details about which constituencies they are / were standing in, and for which parties.
Get all known 2015 candidates
You can also use the search/persons endpoint to find all the candidates that we think are standing in 2015, with this query:
http://yournextmp.popit.mysociety.org/api/v0.1/search/persons?q=_exists_:standing_in.2015.post_id
(This question was raised on the Democracy Club Google Group, which may be of interest if you're developing software that uses the YourNextMP data.)
