Third party integration with Measurements
For the case where a third party needs to access measurements on a supply point,
the proper way to achieve this is by setting up an OAuth Application for them on
the support site. You will need the OAUTH_MANAGER
permission to do this.
API_ENGINEER
alone isn't enough.
Steps to setup an OAuth application
- Access the OAuth application page on the Support Site .
- Create application - filling out the application name as appropriate.
- We want Confidential client for Client type. This should be the default.
-
SAVE THE SECRET KEY.
This secret key is like a password. Kraken cannot retrieve this key, it can only give you a new key. The old key will not work once this occurs, and your clients will need to update their environment variables will this new key. - Select the Client credentials grant for the authorization grant type.
- Leave the Allowed URIs blank, client credentials clients don't require this field.
- Select
THIRD_PARTY_UTILITY_USAGE_DATA_VIEWER
as the API Role. - Leave the skip authorization checkbox unchecked.
Your Application during setup should look like this.
- Create the application and share the secret key in a secure way with the developers who need access to it.
Your application post setup should look like this. This is where you will get the client_id.
-
Make sure the permissions list is exactly the ones above. If they aren't, navigate to the
API Roles/Permissions config page
to be sure that
THIRD_PARTY_UTILITY_USAGE_DATA_VIEWER
has theCAN_VIEW_DETAILED_USAGE
and theCAN_QUERY_PROPERTY
permissions associated with it. This API Role and these permissions are Kraken core objects, and your Kraken will already be able to use them; however, it's possible that your Kraken has not applied these permissions to this role yet. -
Share the application's
client_id
andsecret_key
with the devs that need them! Once they have these and the permissions in step 12 are set, they can be granted a Kraken token and start getting measurements!
Get a Kraken token
Auth server
Receiving any output from most Krakens APIs will require a Kraken token for
access. Account Users are granted these tokens when they login with their
email and password. OAuth Applications will use the auth server's /token/
REST endpoint. See the Python example below.
import requests
def print_token(client_id: str, client_secret: str):
response = requests.post(
"https://auth.octopus.energy/token/",
data={
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
},
)
tokens = response.json()
print(tokens["access_token"])
if name == "__main__":
client_id = "auth_app_client_id_here"
client_secret = "auth_app_client_secret_here"
print_token(client_id, client_secret)
Once you have this token, you'll add it to your API request in the headers tab like so. You may need to refresh this page if the GraphiQL interface is not loading.
{
"Authorization": "your-kraken-token-here"
}