> For the complete documentation index, see [llms.txt](https://manual.firstresonance.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.firstresonance.io/api/access-tokens.md).

# Access Tokens

Get and use access tokens to make API calls

### Step 1 - Generate an API key

Follow the [steps here](/api/api-keys.md) to create an API key.

The API key will include a **clientId** and **clientSecret.**

### Step 2 - Get an access token

Make the API call shown below and update the following variables:

* CLIENT\_ID: the **clientId** from the previous step
* CLIENT\_SECRET: the **clientSecret** from the previous step
* AUTH\_SERVER: The URI for the auth server (see table below)

| App URI                                                                   | Auth Server                          | API Endpoint                                  |
| ------------------------------------------------------------------------- | ------------------------------------ | --------------------------------------------- |
| <p>staging.firstresonance.io</p><p>or</p><p>sandbox.firstresonance.io</p> | staging-auth.buildwithion.com        | <https://staging-api.buildwithion.com>        |
| app.firstresonance.io                                                     | auth.buildwithion.com                | <https://api.buildwithion.com>                |
| <p>staging.ion-gov.com</p><p>or</p><p>sandbox.ion-gov.com</p>             | auth-staging-gov.buildwithion.com    | <https://api-staging-gov.buildwithion.com>    |
| app.ion-gov.com                                                           | auth-production-gov.buildwithion.com | <https://api-production-gov.buildwithion.com> |
| staging.ion-aus.com                                                       | auth-staging-aus.buildwithion.com    | <https://api-staging-aus.buildwithion.com>    |
| app.ion-aus.com                                                           | auth-production-aus.buildwithion.com | <https://api-production-aus.buildwithion.com> |

```
$  curl -X POST \
        --data-urlencode "grant_type=client_credentials" \
        -d "client_id=CLIENT_ID" \
        -d "client_secret=CLIENT_SECRET" \
    https://<AUTH_SERVER>/realms/api-keys/protocol/openid-connect/token
```

[Here is a script ](https://github.com/FirstResonance/ion-examples/blob/master/utilities/api.py)to get your access token via python. We also have our public repository linked below for some sample scripts.

We have a [public repository published](https://github.com/FirstResonance/ion-examples) for some API queries via python scripts.

The below also shows a very basic python script to query runs from ION.

To use, replace the following:

* ACCESS\_TOKEN: the **access token** from the previous step
* API\_ENDPOINT: The API endpoint for each environment are listed in the table above.

```python
import requests
from urllib.parse import urljoin

access_token = <ACCESS_TOKEN>
api_endpoint = <API_ENDPOINT>


headers = {
    'Authorization': f'{access_token}',
    'Content-Type': 'application/json'
}

GET_RUNS = '''
{
    runs(first: 10) {
        edges {
            node { id title
                steps {
                    id
                    title
                }
            }
        }
    }
}
'''

query = {
    'query': GET_RUNS
}

res = requests.post(urljoin(api_endpoint, 'graphql'), headers=headers, json=query)
print(res.json())
```

If you are using a tool like Postman or Insomnia, be sure to add a `/graphql` to your end point. Example: [`https://staging-api.buildwithion.com/graphql`](https://staging-api.buildwithion.com/graphql)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://manual.firstresonance.io/api/access-tokens.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
