Access Tokens
Get and use access tokens to make API calls

Step 1 - Generate an API key

Follow the steps here 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
staging.firstresonance.io
or
sandbox.firstresonance.io
staging-auth.buildwithion.com
https://staging-api.buildwithion.com
app.firstresonance.io
auth.buildwithion.com
https://api.buildwithion.com
staging.ion-gov.com
or
sandbox.ion-gov.com
staging-auth.ion-gov.com
https://staging-api.ion-gov.com
app.ion-gov.com
auth.ion-gov.com
https://api.ion-gov.com
$ curl -X POST \
--data-urlencode "grant_type=client_credentials" \
-d "client_id=CLIENT_ID" \
-d "client_secret=CLIENT_SECRET" \
https://<AUTH_SERVER>/auth/realms/api-keys/protocol/openid-connect/token
Here is a script to get your access token via python.
import requests
from urllib.parse import urljoin
from config import config
# Set authentication and server parameters
# Refer here for auth servers and api endpoints: https://manual.firstresonance.io/api/access-tokens
API_URL = 'https://staging-api.buildwithion.com'
AUTHENTICATION_SERVER = 'staging-auth.buildwithion.com'
def get_access_token():
"""Get accesss token to use in API calls."""
payload = {
'grant_type': 'client_credentials',
'client_id': config['CLIENT_ID'],
'client_secret': config['CLIENT_SECRET'],
'audience': API_URL
}
headers = {'content-type': 'application/x-www-form-urlencoded'}
auth_url = urljoin(f'https://{AUTHENTICATION_SERVER}', '/auth/realms/api-keys/protocol/openid-connect/token', 'oauth/token')
res = requests.post(auth_url, data=payload, headers=headers)
if res.status_code != 200:
raise RuntimeError('An error occurred in the API request')
return res.json()['access_token']

Step 3 - Use the API

We have a public repository published 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.
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())
Last modified 1mo ago
Copy link
On this page
Step 1 - Generate an API key
Step 2 - Get an access token
Step 3 - Use the API