Sunlight Labs API Documentation
This page provides information on directly interfacing with the Sunlight Labs API, note that all calls require an API key.
If you don't already have an API key, registration is fast and simple: Register for your Sunlight Labs API key now!Technical Information
The Sunlight Labs API is RESTful and the preferred output format is JSON, although XML is available as well.
The base URL for all calls to the API is http://services.sunlightlabs.com/api/ and calling an API method looks like:
http://services.sunlightlabs.com/api/api.method.format?apikey=YOUR_API_KEY¶ms
- api.method: any of the methods listed below.
- .format: .xml or .json, if omitted defaults to JSON
- YOUR_API_KEY: the API key you received when signing up
- params: the appropriate parameters to the API method
All API methods return a JSON or XML container named response that contains the object(s) returned by the appropriate API call. For detailed output examples view the specific documentation a particular method.
If an error is encountered the HTTP status code will be set to 400 and a plain text string describing the error is returned regardless of output format. If authentication fails due to a missing or invalid key the HTTP status code 403 is used.
Methods
The Sunlight Labs API currently provides the following methods:Legislator Methods
These methods relate to US Representatives and Senators, providing basic contact information as well as all the various IDs we track for legislators.- legislators.get: get all information on a single legislator
- legislators.getList: get information on all legislators meeting certain requirements
- legislators.allForZip: get information on all legislators that represent some portion of a given zip code (typically 2 senators + 1 or more representatives)
District Methods
These methods relate to Congressional districts, providing lookups to obtain district information from a zipcode or latitude and longitude.- districts.getDistrictsFromZip: get district(s) that a given zip code falls within
- districts.getZipsFromDistrict: get zip codes that fall within a given district
- districts.getDistrictFromLatLong: get district that contains a location identified by a latitude/longitude
More methods are coming soon providing enhanced functionality, the goal in phase one of the new API was to replace the most-used functionality from the original labs API.