Documentation
API Endpoints
Listing Precincts
Get a list of Precinct. By default, we return a paginated list all precincts across all elections, which problaby isn't very useful to you, so you probably want to include some query parameters to filter the list for the precincts you actually want.
HTTP Request
GET /v1/precincts
Examples
- Get a list of all Precincts:
- https://api.ballotapi.org/v1/precincts
- Get a list of Precincts for a specific election:
- https://api.ballotapi.org/v1/precincts?elections=1238es8f
- Get a list of Precincts for a specific contest:
- https://api.ballotapi.org/v1/precincts?contests=3094ur4u2e
- Get a district map (i.e. merged geometry of the precinct list) for a specific contest:
- https://api.ballotapi.org/v1/precincts?contests=3094ur4u2e&extra=merge_geos
Query Parameters
Parameter | Format | Description | Example |
---|---|---|---|
ids
|
String | A comma separated list of specific Precinct ids to include in the response. |
ids=49uhe3,493u03-5
|
ocd_ids
|
OCD-ID | Filter by a comma separated list of specific Open Civic Data Identifers for precincts. |
ocd_ids=ocd-jurisdiction%2F...
|
elections
|
String | Filter by a comma separated list of Election ids. |
elections=08h31-0,i5uu03
|
contests
|
String | Filter by a comma separated list of Contest ids. |
contests=aaaa12,bbbb13
|
extra
|
String |
A comma separated list of extra values you want
to include in the
Options are:
|
extra=merge_geos |
Merge Geometries
If you include the
extra=merge_geos
query parameter in your request, we will merge all of
the areas of the resulting precincts and return that
merged geometry as a
GeoJSON
object in the
extra
results parameter. This is useful for generating district maps.
Example merged geometry result:
{ "type": "response", "data": [...], "next": "...", "extra": { "merge_geos": { "type": "MultiPolygon", ... }, }, "timestamp": "...", "url": "..." }
NOTE: We merge the results of all
the Precinct results for your request, not just the precincts
shown on the first page of results. That way, you don't need
to page through the results to get a full district map.
If you don't want to merge all of the results, use the
ids
query parameter to
specify exactly what precincts you want us to merge.
NOTE: In the
next
results parameter we do not inlcude the
merge_geos
parameter. So if you start paging through the precint results,
you'll only see the merged geometry on the first page. We do this
so we're not generating full district maps on every page request.
Response
We will return the results of your request as a
Response object
with the data
attribute as the list of Precincts.
Responses can be paginated!
Be sure to check the
next
attribute for the next page of data.
Example response:
{ "type": "response", "data": [ { "type": "precinct", "id": "345-6", "ocd_id": null, "election_id": "123-4", "voting_info": {...}, "geo": {...}, }, ... ], "next": "https://api.ballotapi.org/...", "extra": {}, "timestamp": "2018-01-01T00:00:00+00:00", "url": "https://api.ballotapi.org/..." }
HTTP Response Codes
Code | Response Format | Description |
---|---|---|
200
|
Response | Successful request. |
400
|
Error Response | The query parameters you included were invalid. The Error Response will include a message describing exactly was invalid. |
429
|
N/A |
You are making too many requests to the API. Check the
Retry-After header for how many seconds to
wait until trying the request again. See our docs on
Rate Limiting.
|
500
|
N/A | An internal server error occurred. We log these errors and try to fix them quickly, so if you keep getting 500 errors for a few days, please email us. |
503
|
N/A | We are down for maintenance. Please try your request again in a few minutes. |
504
|
N/A | Your request timed out. Please try your request again in a few minutes. |