Nekmo / amazon-dash

Hack your Amazon Dash to run what you want.
MIT License
816 stars 69 forks source link

Using headers on Url Webhook #165

Closed florie1706 closed 3 years ago

florie1706 commented 3 years ago

Put an x into all the boxes [ ] relevant to your issue (like this: [x])

What is the purpose of your issue?

Description

I use this command to trigger a shelly smart relay on linux:

curl -s --header "Authorization: Basic $AUTH" http://$SHELLYIP/settings | jq .device.type | cut -d'"' -f2

whrer $AUTH is username:password as base64 encrypted. This works perfectly.

My amazon-dash.yml which works looks like this:

MAC-ADDRESS: name: Shelly1 url: 'http://USERNAME:PASSWORD@192.168.1.2/relay/0?turn=on' method: post content-type: json

But actually I would like to use it the same stlye as my curl command, but when I modify my yml like this:

MAC-ADDRESS: name: Shelly1 url: 'http://192.168.1.2/relay/0?turn=on' method: post headers: '{"Authorization": "Basic", "XXXXXXXXXXXXXXXXXXXXX"}' content-type: json

I tried the headers line in different style, but I always get the same error:

[Error] Amazon Dash Exception (InvalidConfig):, The configuration file is invalid (/config/amazon-dash.yml). Check the file and read the documentation. '{"Authorization": "Basic", "XXXXXXXXXXXXXXXXXXXXXXXX=="}' is not of type 'object', , Failed validating 'type' in schema['properties']['devices']['patternProperties']['^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$']['properties']['headers']:, {'type': 'object'}, , On instance['devices']['MAC-ADDRESS']['headers']:, '{"Authorization": "Basic", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=="}',

Is it even possible to use it, like I think to use it :) ?

jacobrichard commented 3 years ago

There is an example of this here: https://github.com/Nekmo/amazon-dash/blob/develop/amazon_dash/install/amazon-dash.yml#L24

I have not tested this, but it appears that your quoting of the configuration item under header is causing it to be a string not an object. Make sure that it looks something like this. Notice no quotes around the braces, and the header should be in format key: value -- in this case the key is "Authorization" and the value is "Basic XXXXXXXXXXXXXXXXXXXXX".

headers: {"Authorization": "Basic XXXXXXXXXXXXXXXXXXXXX"}

Hopefully that helps.