API

Our API is located at api.codefordemocracy.org. Our API helps you get to the raw data behind our tools without needing to use the front-end interface. Get started by viewing the available endpoints or generating access credentials using the portal at account.codefordemocracy.org.

Code Samples

You can get started with sending requests quickly using the following wrapper functions in python. Just fill in your client_id and client_secret.

from urllib.parse import urlencode
import requests
import json

# set your credentials
client_id = "XXXXXXXXXXXXXXXXXXXXXXX"
client_secret = "XXXXXXXXXXXXXXXXXXXXXXX"

# this function gets the response from our API
def post(endpoint, body):
    url = "https://api.codefordemocracy.org"
    response = requests.post(url+endpoint, data=json.dumps(body), auth=(client_id, client_secret))
    if response.status_code == 200:
        return json.loads(response.text)
    return []

For example, you can use this code to print the cmte_id for 100 Lobbyist/Registrant PACs:

# set up your API call
endpoint = "/graph/search/committees/"
body = {
    "attributes": {
        "cmte_dsgn": "B"
    },
    "pagination": {
        "limit": 100
    }
}

# get the response
elements = post(endpoint, body)

# print the cmte_ids from the elements
for element in elements:
    print(element["properties"]["cmte_id"])

Our API is open source! See the API repository on GitHub and inspect the code for exact details on how we calculate each endpoint.

Last updated