# API

Our API is located at [api.codefordemocracy.org](https://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](https://api.codefordemocracy.org/view/endpoints/) or generating access credentials using the portal at [account.codefordemocracy.org](https://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`.

```python
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:

```python
# 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"])
```

{% hint style="info" %}
Our API is open source! See the [API](https://github.com/codefordemocracy/api) repository on GitHub and inspect the code for exact details on how we calculate each endpoint.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.codefordemocracy.org/data/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
