Sunlight Labs
Project of The Sunlight Foundation    
Read the labs blog

SunlightLabs API

Your API keys

people.reps.getRepFromDistrict

Get the ID of the representative for a given district

Arguments

These are all $_GET parameters.

state (required)

The state's abbreviation

district (required)

The district's number. District numbers less than 10 are single digit, ie "3" not "03"

apikey (required)

your individual API key

metadata (optional)

&metadata=true provides detail about source, last update of the information etc. Click here for details

output (optional)

&output=json is set by default. You can also use &output=xml

Example Call
http://api.sunlightlabs.com/people.reps.getRepFromDistrict.php?state=MD&district=3
&apikey=23kj234kjb3kjbcl87ds

says give me the ID of the represenative for district MD03

Example Response

For the default JSON:

{ "state": "MD", "district": "3", "entity_id": "fakeopenID352" }
For XML:
<results>
  <state>MD</state>
  <district>3</district>
  <entity_id>fakeopenID352</entity_id>
</results>

Error Codes

If there is an error: a plain text string will be returned:

100: invalid API key

The API key was invalid

101: API key not valid for this method

Not permitted to call this particular method with this particular API key

202: invalid combined user input data

The state abbreviation + district number was not valid

203: invalid state

The state abbreviation was not valid

204: invalid disitrict

The district was not a number