#Rest Sensor useage problem

1 messages · Page 1 of 1 (latest)

abstract skiff
#

Good afternoon
I use a cloud service that allows me to get data via api

to do this, i need to log in using their method, as a result they give me a token
the token is deleted after 20 minutes of inactivity
There is a login, password, post method

i would like to set up a RESTful Sensor to get these data in homeassistant

tried to do like this:

sensor:
  - platform: rest
    resource: https://api.owencloud.ru/v1/auth/open
    method: POST
    username: ***@gmail.com
    password: *****
    authentication: basic
#

as a result I have this error:

#
{"name":"Exception","message":"Поля login и password обязательны для заполнения","code":0,"status":401,"type":"customException","error_status":2}
coarse moss
#

That error though is a 401, not authorized

coarse moss
#

I'd guess that the issue relates to the token

#

Likely you need to authenticate using something other than basic auth (like you're doing)

cosmic reef
#

Or you might need to base64 encode the username:password and place it in a header titled Authorization with a prefix of Bearer

#

If it support's basic auth

abstract skiff
#

right, to work with this api i need to get a token. in node-red or using http-post in the browser I get it, I can't transfer it to sensor

I think it's a syntax problem

abstract skiff
coarse moss
#

Well, the problem is that HA isn't going to store that token

#

Not in a way you can then use

abstract skiff
#

I also get the token via api

cosmic reef
#

Unless you already have it in which case you could store it in secrets. But then you have to rely on the token not expiring

abstract skiff
#

anyway, how do i form a request with header ? something like this:

#
msg.headers={ 
    'Authorization':  'Bearer T1d2kL66IIPgjNLf8AGXyHMV6-QyZYJ6',
    'Content-Type': 'application/x-www-form-urlencoded'
};```
#

this is node-red

#

something like:

sensor:
  - platform: rest
    resource_template: http://IP_ADDRESS/{{ now().strftime('%Y-%m-%d') }}
    headers:
      Authorization: >
        Bearer {{ states("input_text.my_access_token") }}
cosmic reef
#

In the case of the restful sensor it may be doing the proper Basic auth already. But that is how you would provide an access token. you have stored elsewhere. Though I'd recommend saving it as a secret rather than a input_text