All Collections
APIs and Data Integrations
Verdigris API usage with Python
Verdigris API usage with Python

How to use Verdigris API with python requests

S
Written by Support
Updated over a week ago

Head over to our API Docs

Step 1 - Head to our admin console, click on "Create New Key" to generate an API key ; save the "Client ID" and "Client Secret" for API usage.

Note: You will need to create a new API key if you did not grab them. We can not get it for you after your API key is created.

Step 2 - Open a new jupyter notebook  to use with Python 3 

Step 3 - Replace "client_id": xxxx and "client_secret": xxxx with your generated Client ID and Client Secret from Step 1

def get_bearer_token():
""" Gets an authorization token for use with the Verdigris API. Expires in 1 hour. """
    url = 'https://auth.verdigris.co/oauth/token'
    header = {'Content-Type': 'application/json'}
    body = {
    "client_id": "xxxx",
    "client_secret": "xxxx",
    "grant_type": "client_credentials",
    "audience": "https://api.verdigris.co/"
    }
    try:
        resp = requests.post(url, json.dumps(body), headers=header).json()
        return resp["access_token"]
    except:
        return resp

### Get Authorization Token ###
bearer_token_response = get_bearer_token()
if type(bearer_token_response) == str:
    header_auth = {'Authorization': f'Bearer {bearer_token_response}'}
else:
    print(f"Authentication Request Failed:\n{bearer_token_response}")

Example for calls that require no parameters (using Core API)

GET /circuits/

import requests

url = "https://api.verdigris.co/core/v1/circuits/"
response = requests.get(url, headers=header_auth)
response.json()

Example for calls that require parameters (using Data API)

GET /power/circuits/

import requests

url = 'https://api.verdigris.co/data/v4/power/circuits'
payload = {
    'ids':'12345, 23456',
    'start_time':'2020-10-8T:20:55:00Z',
    'end_time':'2020-10-8T:21:55:00Z',
    'interval':'15m',
    'timestamp_format':'iso8601'
}
response = requests.get(url, params = payload, headers = header_auth)

response.json()

Did this answer your question?