LogoLogo
  • Introduction
  • Tools
    • Overview
    • Workflows
    • Recipes
    • Tutorials
  • Data
    • Methodology
    • API
  • Links
    • GitHub
Powered by GitBook
On this page

Was this helpful?

  1. Data

API

PreviousMethodology

Last updated 3 years ago

Was this helpful?

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

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 repository on GitHub and inspect the code for exact details on how we calculate each endpoint.

api.codefordemocracy.org
viewing the available endpoints
account.codefordemocracy.org
API