Currently the Sunlight Labs API provides two methods for obtaining information about legislators: legislators.get and legislators.getList. Both of these methods operate in essentially the same way, the main difference being that legislator.get returns a single legislator (or an error if the query would have resulted in multiple legislators) and legislator.getList returns a list of legislators (a list of size one is allowed). In other words, legislator.get is purely a convenience method to avoid dealing with a list of values when only one value is needed.
One or more parameters should be provided to a call to legislators.get or legislators.getList. Any parameters constrain the legislators which are returned, for example state=NY&party=R returns all Republicans from the state of New York whereas lastname=Pelosi would return any Legislators with the last name Pelosi.
See http://groups.google.com/group/sunlightlabs-api-discuss/browse_thread/thread/e166c9cb755f4bd2?hl=en and the preceding thread http://groups.google.com/group/sunlightlabs-api-discuss/msg/05cfa8f1780834ca?hl=en for discussions on identifiers relevant to legislators. The Sunlight Foundation had introduced its own ID for legislators, but abandoned that ID. In many cases, the bioguide_id works well to synch data from sunlight.
When using legislators.getList it is possible to include multiple values for a single parameter. Doing so looks like:
legislators.getList?lastname=Obama&lastname=McCain&all_legislators=1
This query would return both 2008 presidential candidates.
This can help combine calls to reduce the overhead for example if you have a list of IDs that you need to get information on.
By default, only current legislators (where in_office=1) are included in results from legislator.get or legislator.getList. If you are looking for information on former legislators with entries in the API be sure to include an &all_legislators=true parameter. When all_legislators is specified legislators with in_office=0 are included as well.
Errors are indicated by setting the HTTP status code to 400 and returning a text string describing the error. The following errors may be encountered via legislators.get and legislators.getList:
Legislators are returned either in XML or JSON with all of the fields listed below:
The following fields are both available as parameters and also returned in the Legislator data type: