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.
1
from urllib.parse import urlencode
2
import requests
3
import json
4
5
# set your credentials
6
client_id = "XXXXXXXXXXXXXXXXXXXXXXX"
7
client_secret = "XXXXXXXXXXXXXXXXXXXXXXX"
8
9
# this function gets the response from our API
10
def post(endpoint, body):
11
url = "https://api.codefordemocracy.org"
12
response = requests.post(url+endpoint, data=json.dumps(body), auth=(client_id, client_secret))
13
if response.status_code == 200:
14
return json.loads(response.text)
15
return []
Copied!
For example, you can use this code to print the cmte_id for 100 Lobbyist/Registrant PACs:
1
# set up your API call
2
endpoint = "/graph/search/committees/"
3
body = {
4
"attributes": {
5
"cmte_dsgn": "B"
6
},
7
"pagination": {
8
"limit": 100
9
}
10
}
11
12
# get the response
13
elements = post(endpoint, body)
14
15
# print the cmte_ids from the elements
16
for element in elements:
17
print(element["properties"]["cmte_id"])
Copied!
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 modified 6mo ago
Copy link
Contents
Code Samples