CivicAPI Documentation: Difference between revisions

From Computernewb Wiki
Jump to navigation Jump to search
No edit summary
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
WIP documentation of ElectionsAPI. ElectionsAPI, as the name suggests, is an API which provides political data, both for US and international.
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.
Requests are rate-limited to prevent abuse.


==election==
==upcomingraces==
The <code>election</code> endpoint will give you access to election information, both historic and current.
The <code>/api/v1/upcomingraces</code> endpoint will give data for upcoming races data. This data currently goes up until the end of 2025, incrementing each year.


*Example URL: <code>https://computernewb.com/civicapi/api/v1/upcomingraces</code>
===/v1/election/{country}/{election}/getyears===
*Example output:
This endpoint can be used to get a list of valid election years.
<pre>
{
"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."
}
]
}
</pre>


===Parameters===
Example URL: <code>https://computernewb.com/election/api/v1/election/kp/parliament/getyears</code>
*<code>election_name</code> - Name of the election
*<code>election_type</code> - The type of election. Current valid types are: <code>Statewide</code>, <code>Local</code>, <code>General</code>, and <code>Referendum</code>.
*<code>date</code> - The date of the election.
*<code>description</code> - Contains a small description of the election.


==race==
===/v1/election/{country}/{election}/{year}===
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.
This can be used to fetch information about a country-wide election. The <code>year</code> argument can be used to narrow down the results to a specific year. If one isn't specified, it will return all the elections found.


* Example URL: <code>https://computernewb.com/civicapi/api/v1/race/us/pa/presidential/1789</code>
Valid <code>election</code> arguments are <code>presidential</code>, <code>parliament</code>, and <code>governor</code>


====Parameters====
===Parameters===
*<code>election_name</code> - The name of the election
*<code>race_id</code> - The race ID
*<code>election_type</code> - The type of election. Currently, valid election types are <code>popular</code>, <code>primary</code>, <code>parliament</code>, and <code>electoral</code>.
*<code>country</code> - The name of the country the election is taking place in, in ISO 3166 format
*<code>percent_reporting</code> - Specifies the number of precincts reporting.
*<code>state</code> - If applicable, the name of the state the election is taking place in, also in ISO 3166 format.
*<code>type</code> - The type of election. Valid election types are: <code>presidential</code>, <code>presidential_round2</code>, <code>governor</code>, <code>house</code>, <code>regent</code>, <code>parliament</code>, <code>senate</code>, <code>referendum</code>, <code>mayor</code>,<code>primary</code>, <code>prime_minister</code>, <code>papal</code>, <code>secretary_of_state</code>, <code>attorney_general</code>, <code>state_house</code>, <code>state_senate</code>, and <code>treasurer</code>.
*<code>votes_needed</code> - Will list the number of votes needed in a parliamentary or electoral vote to win the election. This parameter does not exist if <code>election_type</code> is <code>popular</code>.
*<code>round</code> - Specifies the current round of voting in the election.
*<code>year</code> - The year of the election.
*<code>data</code>
*<code>is_snap_election</code> - Specifies if the election is a snap election.
**<code>election_name</code>:
*<code>is_ongoing</code> - Specifies if the election is currently ongoing.
***<code>en_US</code> - The name of the election (in American English).
*<code>has_map</code> - Specifies if the election supports a map. A map can be generated with <code>/v1/election/{country}/{election}/{year}/map</code> (more information below)
*<code>map</code> - Specifies the map file to use.
**<code>is_snap_election</code> - Specifies if the election is a snap election.
*<code>polls_open</code> - Specifies the date of the polls for the election opening, in Epoch milliseconds.
**<code>is_uncontested</code> - If there is only one (or no) candidate in the race, this will be set to <code>true</code>.
*<code>polls_close</code> - Specifies the date of the polls for the election closing, in Epoch milliseconds.
**<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 it does, you can generate an image of the map by adding <code>?generateMapImage</code> to the URL, or download the SVG directly by adding <code>?getMapSVG</code>.
*<code>term_start</code> - Specifies when the winner's term will begin, in Epoch milliseconds.
*<code>term_end</code> - Specifies when the winner's term will end, in Epoch milliseconds.
**<code>polls_open</code> - The time when the polls open.
*<code>sources</code> - Lists the sources which were used to gather the data.
**<code>polls_close</code> - The time when the polls close.
*<code>candidates</code> - The list of candidates in the race.
**<code>term_begins</code> - Specifies when the elected candidate's term should begin.
**<code>name</code> - Candidate's name
**<code>term_ends</code> - Specifies when the elected candidate's term should end.
**<code>incumbent</code> - Specifies whether the candidate is an incumbent.
**<code>election_type</code> - Specifies the election type.
**<code>write_in</code> - Specifies whether the candidate is a write-in candidate.
**<code>election_scope</code> - Specifies the scope of the election.
**<code>eligible_voters</code> - How many voters were eligible to vote in this election.
**<code>dropped_out</code> - Specifies whether the candidate has dropped out of the race. Only exists if the <code>election_type</code> is <code>primary</code>.
**<code>party</code> - Candidate's party
**<code>percent_reporting</code> - Estimated percentage reporting.
**<code>votes</code> - The number of votes the candidate received
**<code>turnout</code> - The turnout, calculated by the number of votes + <code>eligible_voters</code> turned out.
**<code>last_updated</code> - Specifies when the data was last updated.
**<code>delegates</code> - The number of delegates the candidate received. Normally only exists if the <code>election_type</code> is <code>primary</code>, but one US presidential elections (the 1824 election) also used delegates to elect the president.
**<code>percent</code> - The percentage of votes the candidate received
**<code>round</code> - Specifies the round.
**<code>electoral_votes</code> - The number of electoral votes the candidate received. Only exists if the <code>election_type</code> is <code>electoral</code>.
**<code>sources</code> - Lists the sources used to gather the data.
**<code>district_details</code>:
**<code>seats_won</code> - The number of seats the candidate won. Only exists if the <code>election_type</code> is <code>parliament</code>.
**<code>states_carried</code> - The number of states the candidate received. Only exists if the <code>election_type</code> is <code>electoral</code>.
***<code>district_name</code> - The name of the district.
**<code>contests_won</code> - The number of contests the candidate won. Only exists if the <code>election_type</code> is <code>primary</code>.
***<code>district_country</code> - The country of the district.
**<code>winner</code> - Specifies if the candidate has been declared the winner.
***<code>district_map</code> - The map the district will use if <code>?generateMapImage</code> or <code>?getMapSVG</code> is specified.
**<code>candidates</code>:
*<code>region_results</code> - Results of the states/regions/constituencies/counties/oblasts/etc.
**<code>region</code> - The region
***<code>name</code> - The name of the candidate
***<code>candidates</code> - The list of candidates in the region.
***<code>party</code> - The candidate's party
****<code>name</code> - Candidate's name
***<code>candidate_id</code> - The candidate's ID in the database
****<code>party</code> - Candidate's party
***<code>incumbent</code> - Specifies if the candidate was an incumbent
****<code>votes</code> - The number of votes the candidate 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>percent</code> - The percentage of votes the candidate received
***<code>dropped_out</code> - Specifies if the candidate dropped out of the election.
**<code>electoral_votes</code> - Specifies the number of electoral votes of the region. Only exists if the election_type is <code>electoral</code>.
***<code>write_in_candidate</code> - Specifies if this is a write-in candidate.
**<code>percent_reporting</code> - Specifies the number of precincts reporting in the region.
***<code>winner</code> - Specifies if this candidate won the election.
**<code>winner</code> - The winner of the region.
***<code>candidate_color</code> - The candidate's color (used for maps).
**<code>fill</code> - The region winner's hex color, for filling maps in with.
***<code>votes</code> - The number 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. Only valid for US presidential elections and certain US governor elections.
Example URL: <code>https://computernewb.com/election/api/v1/election/us/presidential/1789</code>
***<code>states_carried</code> - The number of states the candidate has carried.

***<code>seats_won</code> - The number of seats the candidate has won.
===/v1/election/{country}/{election}/{year}/map===
***<code>delegates</code> - The number of delegates the candidate has been awarded.
This endpoint can be used to generate a map. It returns a PNG of a filled out map. This endpoint will only work if <code>has_map</code> is <code>true</code>. Otherwise, it will throw a 404 error.

Example URL: <code>https://computernewb.com/election/api/v1/election/us/presidential/1789/map</code>

===/v1/election/{country}/{election}/{year}/{region}===
This can be used to fetch information about a specific region's election results. The <code>year</code> argument can be used to narrow down the results to a specific year. If one isn't specified, it will return all the elections found.

Valid <code>election</code> arguments are <code>presidential</code> and <code>governor</code>

====Parameters====
*<code>election_name</code> - The name of the election
*<code>election_type</code> - The type of election. Currently, valid election types are <code>popular</code>, <code>primary</code>, <code>parliament</code>, and <code>electoral</code>.
*<code>votes_needed</code> - Will list the number of votes needed in a parliamentary or electoral vote to win the election. This parameter does not exist if <code>election_type</code> is <code>popular</code>.
*<code>percent_reporting</code> - Returns the number of precincts reporting in the election.
*<code>round</code> - Specifies the current round of voting in the election.
*<code>is_snap_election</code> - Specifies if the election is a snap election.
*<code>is_ongoing</code> - Specifies if the election is currently ongoing.
*<code>has_map</code> - Specifies if the election supports a map. A map can be generated with <code>/v1/election/{country}/{election}/{year}/map</code> (more information below)
*<code>map</code> - Specifies the map file to use.
*<code>polls_open</code> - Specifies the date of the polls for the election opening, in Epoch milliseconds.
*<code>polls_close</code> - Specifies the date of the polls for the election closing, in Epoch milliseconds.
*<code>term_start</code> - Specifies when the winner's term will begin, in Epoch milliseconds.
*<code>term_end</code> - Specifies when the winner's term will end, in Epoch milliseconds.
*<code>sources</code> - Lists the sources which were used to gather the data.
*<code>candidates</code> - The list of candidates in the race.
**<code>name</code> - Candidate's name
**<code>incumbent</code> - Specifies whether the candidate is an incumbent.
**<code>write_in</code> - Specifies whether the candidate is a write-in candidate.
**<code>dropped_out</code> - Specifies whether the candidate has dropped out of the race. Only exists if the election_type is <code>primary</code>.
**<code>party</code> - Candidate's party
**<code>votes</code> - The number of votes the candidate received
**<code>percent</code> - The percentage of votes the candidate received
**<code>electoral_votes</code> - The number of electoral votes the candidate received. Only exists if the election_type is <code>electoral</code>.
**<code>states_carried</code> - The number of states the candidate received. Only exists if the election_type is <code>electoral</code>.
**<code>seats_won</code> - The number of seats the candidate won. Only exists if the election_type is <code>parliament</code>.
**<code>delegates</code> - The number of delegates the candidate won. Only exists if the election_type is <code>primary</code>.
**<code>winner</code> - Specifies if the candidate has been declared the winner.
*<code>region_results</code> - Results of the counties/districts/parishes/boroughs/etc.
**<code>region</code> - The region name
***<code>candidates</code> - The list of candidates in the region.
****<code>name</code> - Candidate's name
****<code>party</code> - Candidate's party
****<code>votes</code> - The number of votes the candidate received
****<code>percent</code> - The percentage of votes the candidate received
**<code>electoral_votes</code> - Specifies the number of electoral votes of the region. Only exists if the election_type is <code>electoral</code>.
**<code>percent_reporting</code> - Specifies the number of precincts in the region reporting.
**<code>winner</code> - The winner of the region.
**<code>fill</code> - The region winner's hex color, for filling maps in with.

Example URL: <code>https://computernewb.com/election/api/v1/election/us/governor/2022/mn</code>

===/v1/election/{country}/{election}/{year}/{region}/map===
This endpoint can be used to generate a map. It returns a PNG of a filled out map. This endpoint will only work if <code>has_map</code> is <code>true</code>. Otherwise, it will throw a 404 error.

Example URL: <code>https://computernewb.com/election/api/v1/election/us/governor/2022/mn/map</code>

===/v1/election/{country}/{election}/{year}/{region}/{district}===
This endpoint can be used to fetch results for a specific county/region/district/etc. This does not support the <code>map</code> argument yet.

(not implemented yet; no docs)

==poll==
The <code>poll</code> endpoint will give you the latest polls on various issues such as Trump vs. Harris, Biden approval rating, Harris approval rating, etc.

(not implemented yet; no docs)

==predictions==
The <code>predictions</code> endpoint returns forecasts on the 2024 US presidential race. Only supports presidential races for now but others may be supported in the future.

===/v1/predictions/{type}/{source}===

====Parameters====
*<code>name</code> - Name of the forecast
*<code>url</code> - URL of the forecast
*<code>last_updated</code> - When the forecast was last updated.
*<code>votes_needed</code> - Votes needed to win
*<code>before_biden_dropout</code> - Returns if the forecast was done before Joe Biden dropped out of the race.
*<code>map</code> - Specifies the map to use.
*<code>candidates</code> - The list of candidates in the race.
**<code>name</code> - Candidate's name
**<code>incumbent</code> - Specifies whether the candidate is an incumbent.
**<code>party</code> - Candidate's party
**<code>electoral_votes</code> - The number of electoral votes the candidate received in the prediction
**<code>candidate_color</code> - Specifies the candidate's color on the map
**<code>winner</code> - Specifies if the candidate has been declared the winner.
*<code>region_results</code> - Results of the counties/districts/parishes/boroughs/etc.
**<code>region</code> - The region name
***<code>winner</code> - Specifies the name of the candidate who won the region
***<code>fill</code> Specifies the hex color fill to use on a map

Example URL: <code>http://computernewb.com/election/api/v1/predictions/presidential/polymarket</code>

===/v1/predictions/{type}/{source}/map===
This endpoint can be used to generate a map. It returns a PNG of a filled out electoral map.
Example URL: <code>https://computernewb.com/election/api/v1/predictions/presidential/polymarket/map</code>

==gas==
The <code>gas</code> endpoint returns prices for gas across the US (and maybe other countries in the future).

(not implemented yet; no docs)

==amendment==
The <code>amendment</code> endpoint will return amendments from the US Constitution (and maybe other countries in the future)

===/v1/amendment/{country}/{amendment}===
This can be used to fetch an amendment. This endpoint currently only supports the US Constitution's amendments.
*<code>amendment_name</code> - Name of the amendment
*<code>amendment_full_name</code> - Full title of the amendment
*<code>adopted</code> - Date of adoption, in Epoch milliseconds.
*<code>text</code> - The text of the amendment

Example URLs:
*<code>https://computernewb.com/api/v1/amendment/us/1st</code> - Returns the First Amendment
*<code>https://computernewb.com/api/v1/amendment/us/</code> - Returns all the amendments

Revision as of 00:58, 15 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.

{
  "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 election
  • election_type - The type of election. Current valid types are: Statewide, Local, General, and Referendum.
  • 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.

Parameters

  • race_id - The race ID
  • country - The name of the country the election is taking place in, in ISO 3166 format
  • state - 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, and treasurer.
  • 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_uncontested - If there is only one (or no) candidate in the race, this will be set to true.
    • is_delayed - Will be true if the election has been previously delayed.
    • has_map - Specifies if the election has a map. If it does, you can generate an image of the map by adding ?generateMapImage to the URL, or download the SVG directly by adding ?getMapSVG.
    • 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 ?generateMapImage or ?getMapSVG is specified.
    • candidates:
      • name - The name of the candidate
      • party - The candidate's party
      • candidate_id - The candidate's ID in the database
      • incumbent - Specifies if the candidate was an incumbent
      • is_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. Only valid for US presidential elections and certain US 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.