HTTP Posts with Long Lived Tokens

Hi,

I am using Flic Buttons to execute scripts defined in hassio. I also moved from legacy API to the new authentication. This switch actually broke my HTTP Posts that I cofigured in the flic configuration.

I now attempted to do the same with my long lived token generated from within hassio but can’t get it to work. any idea what i could try? I attached a screenshot, so that you can see which options flic offers me:

1 Like

I have just been through this with my own bash script. Here is what I have working.

curl -X POST -H "Authorization: Bearer $token" \
     -H "Content-Type: application/json" \
     -d "$abbusagestring" \
     "$server"/api/states/sensor.abb_usage

so the first 2 lines might be your header… the string (JSON) I’n sending is the third line and the last line corresponds with your url where “$server” would be http://ipaddress:8123 or whatever you use to access Home Assistant.

I also have a version using MQTT but if you want anyone else to be able to use it (like if they run hassio) that might not work. Mine populates a sensor called abb_usage as you see in the URL

1 Like

Webhook is not access token.

I now tried the following, but still not success:

Nevermind, I fixed it. It was far more logical than expected.

As there is no api password anymore, just

  1. Shorten the URL accordingly (remove the “?api_password=YOURAPIPASSWORD” part of the URL)
  2. Add as key into Headers “Authorization” (without the " ")
  3. Add as STRING the value “Bearer YOURLONGLIVEDTOKEN” (without the " ")

It looks like this at the end:

This way, all my http posts continue to work with Flic Button presses

I’ve done exactly this and while I can get it to work via curl it fails authentication when using the flic. I have Bearer at the beginning. I don’t see anything wrong in any of my entries… does this still work for you?

I thought maybe they broke something and very long strings like the token might be getting truncated?

Yupp, still working for me. Don’t know what the problem in your case is,though. I am running newest hassio

I. tried turning on debug for homeassistant.components.http.ban but it doesn’t appear to give any more info :confused:

Are you using Android? Maybe that’s the difference?

Good point. Yes, I am using Android for configuring the flics but the communication with the flics takes place with my flic hub.

I came back to it today and got it working on a new hassio install!
As far as I can tell I did nothing differently but I just wanted to let everyone know it can work fine from iOS too.

Hi,

I am also trying to send post to Home Assistant to turn on light for example. I am trying to do this in python but I am missing something.

from requests import post

url = ‘http://192.168.1.xx:8123/api/services/switch/turn_off

headers = {‘authorization’: ‘Bearer TOKEN’,‘content-type’: ‘application/json’}

WHAT ABOUT THIS???WHERE DOES IT GO?? body = {‘entity_id’: ‘switch.fibaro_switch’}

txt04 = post(url, headers=headers)
print(txt04.text)