Custom Addon - Unauthorised when calling http://supervisor/

I have created a custom addon by following the guide, all is good except for the fact that I am unable to communicate with the API and always get 401: Unauthorized

As per the guide, I have added these to the config.yam and rebuilt it:

homeassistant_api: true
hassio_api: true

And also logged (echo) the SUPERVISOR_TOKEN during startup so I am 100% sure it is set.

But when I call the following, it always gives me the Unauthorised error:

curl -X GET -H "Authorization: Bearer ${SUPERVISOR_TOKEN}" -H "Content-Type: application/json" http://supervisor/core/api/config

Also tried calling from python script and that also fails:

from requests import get
import os


url = "http://supervisor/core/api/config"
headers = {
  "Authorization": "Bearer "+TOKEN,
  "content-type": "application/json",
response = get(url, headers=headers)

Any suggestions on what the issue may be ??

1 Like

This is solved.

I am still unable to get the startup script to make the call, but python now works with:

headers = {
  "Authorization": "Bearer {}".format(TOKEN),
  "content-type": "application/json",
1 Like


how do I get the environment variable set?

in my config.yaml is:

hassio_api: true
hassio_role: admin
homeassistant_api: true
host_network: true

and my environment variables printed with os.environ:
environ({'OLDPWD': '/', 'PATH': '/command:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'PWD': '/app_data', 'LC_CTYPE': 'C.UTF-8'})

Looks like nothing is set.
My project: GitHub - FelixMarschall/HA_ProcessMining_Addon at 580b2a861c6ed0b4f58db6e45e85803c873d8441

Do you have any clue, how to set environment variables?