Examples of API Calls (Python, Jupyter Notebook)

Import Python packages

import json, requests, itertools, os
from urllib.parse import urljoin

Load credentials (Request your API key)

secrets = {
    "client_id": "" , #enter your Client ID
    "client_secret": "" #enter your Client Secret
}

Helper methods definition

Call authorization API to get temporary authorization token

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

Prepare needed request header

def prepare_request_header(secrets):
    bearer_token_response = get_bearer_token(secrets["api_client"], secrets["api_key"])
    header_auth = {}
    if type(bearer_token_response) == str:
        header_auth = {'Authorization': f'Bearer {bearer_token_response}'}
    else:
        print(f"Authenication Request Failed:\n{bearer_token_response}")
    return header_auth

Examples for API calls using Core API

base_url = "https://api.verdigris.co/core/v1/"
header = prepare_request_header(secrets)

Get all buildings under an account

buildings_url = urljoin(base_url, "buildings")
buildings = requests.get(buildings_url, headers=header).json()['data']

Get all related panels, breakers, circuits with a given building

buildings_url = urljoin(base_url, "buildings?filter[id]=352&include=panels.breakers.circuits")
response = requests.get(buildings_url, headers=header).json()
buildings = response['data']
included_data = response['included']

Get information for a specific panel

panel_id = 1496
panel_url = urljoin(base_url, f"panels/{panel_id}")
panel = requests.get(panel_url, headers=header).json()['data']

Get information for a specific breaker

breaker_id = 19580
breaker_url = urljoin(base_url, f"breakers/{breaker_id}")
breaker = requests.get(breaker_url, headers=header).json()['data']

Get information for a specific circuit

circuit_id = 31590
circuit_url = urljoin(base_url, f"circuits/{circuit_id}")
circuit = requests.get(circuit_url, headers=header).json()['data']

Examples for getting time series data using Data API

base_url = "https://api.verdigris.co/data/v4/"

Get Energy usage data

entity_type = "buildings"
entity_ids = 352
start_time = "2022-01-01T00:00:00Z"
end_time = "2022-02-01T00:00:00Z"
interval = "1d"
url = urljoin(base_url, f"energy/{entity_type}?ids={entity_ids}&start_time={start_time}&end_time={end_time}&interval={interval}")
res = requests.get(url, headers=header).json()

Get Power usage data

entity_type = "buildings"
entity_ids = 352
start_time = "2022-01-01T00:00:00Z"
end_time = "2022-02-01T00:00:00Z"
interval = "1d"
url = urljoin(base_url, f"power/{entity_type}?ids={entity_ids}&start_time={start_time}&end_time={end_time}&interval={interval}")
res = requests.get(url, headers=header).json()

Ready to start building?

Download Jupyter Notebook