TogaTech Free US Presidential Election API (Backend)

Credit is REQUIRED to use the API. Please make sure to mention the use of this API and a link to https://uselection.togatech.org/ when using the API in your projects (on your project pages that use this API, any documentation for code that uses this API, etc.). Copying the API or fetching data from our API and marking it as your own is STRICTLY FORBIDDEN.

To help keep this API free, we kindly request that you try to limit API calls to 30 seconds per server (get the data for your server and distribute from your server to clients). If we get too many requests as a result of programs calling this API too often, we will either shut down the API or start charging money for its use.

The API is only available for use in backend systems to better distribute the load (servers fetch from the API and distribute the data to clients). We are enforcing this by having no 'Access-Control-Allow-Origin' header.


For questions or help on the API, please email [email protected].


Base URL:

https://uselection.togatech.org/api

GET /data


Parameters:

None

Example (Node.js, ES6):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/data").then(json => {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(err => {
    console.error(err);
});

Example (Node.js, ES5):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/data").then(function(json) {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(function(err) {
    console.error(err);
});

Example (PHP):

$api_base = "https://uselection.togatech.org/api";
$data = json_decode(file_get_contents($api_base . "/data"), true);
/* Manipulate and/or store "$data" */

Sample Response:

{
    "parties":["democratic","republican"],
    "data":{
        "democratic":{
            "color":"#0015BC",
            "candidate":{
                "first_name":"Joe",
                "last_name":"Biden",
                "title":"Former Vice President"
            },
            "vice_president":{
                "first_name":"Kamala",
                "last_name":"Harris",
                "title":"Senator"
            },
            "votes":0
        },
        "republican":{
            "color":"#E9141D",
            "candidate":{
                "first_name":"Donald",
                "last_name":"Trump",
                "title":"Current President"
            },
            "vice_president":{
                "first_name":"Mike",
                "last_name":"Pence",
                "title":"Current Vice President"
            },
            "votes":0
        }
    },
    "called": false
}

GET /metadata


Parameters:

None

Example (Node.js, ES6):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/metadata").then(json => {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(err => {
    console.error(err);
});

Example (Node.js, ES5):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/metadata").then(function(json) {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(function(err) {
    console.error(err);
});

Example (PHP):

$api_base = "https://uselection.togatech.org/api";
$data = json_decode(file_get_contents($api_base . "/metadata"), true);
/* Manipulate and/or store "$data" */

Sample Response:

{
    "democratic":{
        "color":"#0015BC",
        "candidate":{
            "first_name":"Joe",
            "last_name":"Biden",
            "title":"Former Vice President"
        },
        "vice_president":{
            "first_name":"Kamala",
            "last_name":"Harris",
            "title":"Senator"
        }
    },
    "republican":{
        "color":"#E9141D",
        "candidate":{
            "first_name":"Donald",
            "last_name":"Trump",
            "title":"Current President"
        },
        "vice_president":{
            "first_name":"Mike",
            "last_name":"Pence",
            "title":"Current Vice President"
        }
    }
}

GET /parties


Parameters:

None

Example (Node.js, ES6):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/parties").then(json => {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(err => {
    console.error(err);
});

Example (Node.js, ES5):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/parties").then(function(json) {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(function(err) {
    console.error(err);
});

Example (PHP):

$api_base = "https://uselection.togatech.org/api";
$data = json_decode(file_get_contents($api_base . "/parties"), true);
/* Manipulate and/or store "$data" */

Sample Response:

[
    "democratic",
    "republican"
]

GET /votes


Parameters:

None

Example (Node.js, ES6):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/votes").then(json => {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(err => {
    console.error(err);
});

Example (Node.js, ES5):

const rp = require("request-promise");
const api_base = "https://uselection.togatech.org/api";
rp(api_base + "/votes").then(function(json) {
    let data = JSON.parse(json);
    /* Manipulate and/or store "data" */
}).catch(function(err) {
    console.error(err);
});

Example (PHP):

$api_base = "https://uselection.togatech.org/api";
$data = json_decode(file_get_contents($api_base . "/votes"), true);
/* Manipulate and/or store "$data" */

Sample Response:

{
    "democratic":0,
    "republican":0
}