CivicAPI Documentation: Difference between revisions
Jump to navigation
Jump to search
(4 intermediate revisions by the same user not shown) | |||
Line 30: | Line 30: | ||
The <code>/api/v1/race/{country}/{state}/{type}/{year}</code> endpoint will return election data for a specified election. This is valid for both ongoing and historic elections. |
The <code>/api/v1/race/{country}/{state}/{type}/{year}</code> endpoint will return election data for a specified election. This is valid for both ongoing and historic elections. |
||
You can also fetch elections via ID - i.e. <code>/api/v1/race/{id}</code> |
|||
* Example URLs: <code>https://computernewb.com/civicapi/api/v1/race/us/pa/presidential/1789</code> |
|||
* <code>https://computernewb.com/civicapi/api/v1/race/19</code> |
|||
===Parameters=== |
===Parameters=== |
||
Line 42: | Line 45: | ||
***<code>en_US</code> - The name of the election (in American English). |
***<code>en_US</code> - The name of the election (in American English). |
||
**<code>is_snap_election</code> - Specifies if the election is a snap election. |
**<code>is_snap_election</code> - Specifies if the election is a snap election. |
||
**<code> |
**<code>is_disputed</code> - If this election has been disputed by one or more governments or election officials, this will be <code>true</code>. |
||
**<code>is_delayed</code> - Will be <code>true</code> if the election has been previously delayed. |
**<code>is_delayed</code> - Will be <code>true</code> if the election has been previously delayed. |
||
**<code>has_map</code> - Specifies if the election has a map. If |
**<code>has_map</code> - Specifies if the election has a map. If a map is available, you can add <code>?generateMap</code> to the end of the URL to download an SVG map, or generate a PNG with <code>?generateMapPNG</code>. |
||
**<code>polls_open</code> - The time when the polls open. |
**<code>polls_open</code> - The time when the polls open. |
||
**<code>polls_close</code> - The time when the polls close. |
**<code>polls_close</code> - The time when the polls close. |
||
Line 60: | Line 63: | ||
***<code>district_name</code> - The name of the district. |
***<code>district_name</code> - The name of the district. |
||
***<code>district_country</code> - The country of the district. |
***<code>district_country</code> - The country of the district. |
||
***<code>district_map</code> - The map the district will use if <code>? |
***<code>district_map</code> - The map the district will use if <code>?generateMap</code> or <code>?generateMapPNG</code> is specified. |
||
**<code>candidates</code>: |
**<code>candidates</code>: |
||
***<code>name</code> - The name of the candidate |
***<code>name</code> - The name of the candidate |
||
Line 66: | Line 69: | ||
***<code>candidate_id</code> - The candidate's ID in the database |
***<code>candidate_id</code> - The candidate's ID in the database |
||
***<code>incumbent</code> - Specifies if the candidate was an incumbent |
***<code>incumbent</code> - Specifies if the candidate was an incumbent |
||
***<code>is_major</code> - Specifies if the candidate is a major candidate. By our definition, any candidate that received |
***<code>is_major</code> - Specifies if the candidate is a major candidate. By our definition, any candidate that received 7% or more of the vote is considered a "major" candidate. |
||
***<code>dropped_out</code> - Specifies if the candidate dropped out of the election. |
***<code>dropped_out</code> - Specifies if the candidate dropped out of the election. |
||
***<code>write_in_candidate</code> - Specifies if this is a write-in candidate. |
***<code>write_in_candidate</code> - Specifies if this is a write-in candidate. |
||
Line 73: | Line 76: | ||
***<code>votes</code> - The number of votes the candidate received. |
***<code>votes</code> - The number of votes the candidate received. |
||
***<code>percent</code> - The percentage of votes the candidate received. |
***<code>percent</code> - The percentage of votes the candidate received. |
||
***<code>electoral_votes</code> - The electoral votes the candidate received. |
***<code>electoral_votes</code> - The electoral votes the candidate received. Used in United States and Italian presidential elections, as well as certain historic elections in Argentina, Brazil, and United States governor elections. |
||
***<code>states_carried</code> - The number of states the candidate has carried. |
***<code>states_carried</code> - The number of states the candidate has carried. |
||
***<code>seats_won</code> - The number of seats the candidate has won. |
***<code>seats_won</code> - The number of seats the candidate has won. |
||
***<code>delegates</code> - The number of delegates the candidate has been awarded. |
***<code>delegates</code> - The number of delegates the candidate has been awarded. |
||
==search== |
|||
The <code>/api/v1/search</code> endpoint allows you to search for elections. |
Latest revision as of 18:32, 20 November 2024
WIP documentation of CivicAPI. CivicAPI, as the name suggests, is an API which provides political data, both for US and international.
Requests are rate-limited to prevent abuse.
upcomingraces
The /api/v1/upcomingraces
endpoint will give data for upcoming races data. This data currently goes up until the end of 2025, incrementing each year.
- Example URL:
https://computernewb.com/civicapi/api/v1/upcomingraces
- Example output:
{ "Austria": [ { "election_name": "Styrian state elections", "election_type": "Statewide", "date": "2024-11-24T00:00:00", "description": "State elections in the Austrian state of Styria will be held on November 24." } ] }
Parameters
election_name
- Name of the electionelection_type
- The type of election. Current valid types are:Statewide
,Local
,General
, andReferendum
.date
- The date of the election.description
- Contains a small description of the election.
race
The /api/v1/race/{country}/{state}/{type}/{year}
endpoint will return election data for a specified election. This is valid for both ongoing and historic elections.
You can also fetch elections via ID - i.e. /api/v1/race/{id}
- Example URLs:
https://computernewb.com/civicapi/api/v1/race/us/pa/presidential/1789
https://computernewb.com/civicapi/api/v1/race/19
Parameters
race_id
- The race IDcountry
- The name of the country the election is taking place in, in ISO 3166 formatstate
- If applicable, the name of the state the election is taking place in, also in ISO 3166 format.type
- The type of election. Valid election types are:presidential
,presidential_round2
,governor
,house
,regent
,parliament
,senate
,referendum
,mayor
,primary
,prime_minister
,papal
,secretary_of_state
,attorney_general
,state_house
,state_senate
, andtreasurer
.year
- The year of the election.data
election_name
:en_US
- The name of the election (in American English).
is_snap_election
- Specifies if the election is a snap election.is_disputed
- If this election has been disputed by one or more governments or election officials, this will betrue
.is_delayed
- Will betrue
if the election has been previously delayed.has_map
- Specifies if the election has a map. If a map is available, you can add?generateMap
to the end of the URL to download an SVG map, or generate a PNG with?generateMapPNG
.polls_open
- The time when the polls open.polls_close
- The time when the polls close.term_begins
- Specifies when the elected candidate's term should begin.term_ends
- Specifies when the elected candidate's term should end.election_type
- Specifies the election type.election_scope
- Specifies the scope of the election.eligible_voters
- How many voters were eligible to vote in this election.percent_reporting
- Estimated percentage reporting.turnout
- The turnout, calculated by the number of votes +eligible_voters
turned out.last_updated
- Specifies when the data was last updated.round
- Specifies the round.sources
- Lists the sources used to gather the data.district_details
:district_name
- The name of the district.district_country
- The country of the district.district_map
- The map the district will use if?generateMap
or?generateMapPNG
is specified.
candidates
:name
- The name of the candidateparty
- The candidate's partycandidate_id
- The candidate's ID in the databaseincumbent
- Specifies if the candidate was an incumbentis_major
- Specifies if the candidate is a major candidate. By our definition, any candidate that received 7% or more of the vote is considered a "major" candidate.dropped_out
- Specifies if the candidate dropped out of the election.write_in_candidate
- Specifies if this is a write-in candidate.winner
- Specifies if this candidate won the election.candidate_color
- The candidate's color (used for maps).votes
- The number of votes the candidate received.percent
- The percentage of votes the candidate received.electoral_votes
- The electoral votes the candidate received. Used in United States and Italian presidential elections, as well as certain historic elections in Argentina, Brazil, and United States governor elections.states_carried
- The number of states the candidate has carried.seats_won
- The number of seats the candidate has won.delegates
- The number of delegates the candidate has been awarded.
search
The /api/v1/search
endpoint allows you to search for elections.