Hi, i tried this action in Tasker and it works. I can't get it working in Automagic instead. I'm not sure how to write data in http request form. Can someone help me?
Attached is the screenshot from Tasker. How can i use that data in Automagic http request action?
http request
Moderator: Martin
http request
- Attachments
-
- photo_2020-01-20_14-03-26.jpg (52.21 KiB) Viewed 10818 times
Re: http request
Use Action HTTP Request
URL : https//MY_IP_ADDRESS:8123/api/services/light/turn_on
Request Method : POST
Content Type : General Text - text/plain
Data : {"entity_id":"light.rgbw_1"}
Custom HTTP headers : tick and put
Authorization:Bearer MY_LONG_LIFE_CERTIFICATE
Put condition debug dialog after this to spot any possible error. You can check {response} value for result.
URL : https//MY_IP_ADDRESS:8123/api/services/light/turn_on
Request Method : POST
Content Type : General Text - text/plain
Data : {"entity_id":"light.rgbw_1"}
Custom HTTP headers : tick and put
Authorization:Bearer MY_LONG_LIFE_CERTIFICATE
Put condition debug dialog after this to spot any possible error. You can check {response} value for result.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: http request
Hi, thank you for your reply. Tha is what I made.. But doesn't work. This js the log
It seems the connection is ok, but message is not good. Any idea? Same Body in Tasker works fine..Re: http request
So the only problem now is the JSON. Forgot that you can't use JSON directly there, because Automagic will Automagically parse the curly braces to a variable/expression. viewtopic.php?f=5&t=3088&p=15992&hilit= ... mat#p15992
The strange way to use it directly is to single quote it (must be single quote) and surround it by another curly braces.
Hence the Data should be
But I typically prepare the json before and then use function toJSON() before passing to the request. (that's why I forgot about this already). To do so, create a new map/list as your data should be. Your json is a single level map type with key-value. So it should be
Then use {js} in the Data field. IMHO, this is the recommend good practice (in Automagic) to pass JSON to the http request. toJSON() will ensure any special character will be escaped properly.
The strange way to use it directly is to single quote it (must be single quote) and surround it by another curly braces.
Hence the Data should be
Code: Select all
{'{"entity_id":"light.rgbw_1"}'}
Code: Select all
object = newMapFromValues("entity_id", "light.rgbw_1");
js = toJSON(object);
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: http request
Thank you, works great. i used the second way. Tasker is very painful! I never wanted to use it.Desmanto wrote: ↑21 Jan 2020 05:53So the only problem now is the JSON. Forgot that you can't use JSON directly there, because Automagic will Automagically parse the curly braces to a variable/expression. viewtopic.php?f=5&t=3088&p=15992&hilit= ... mat#p15992
The strange way to use it directly is to single quote it (must be single quote) and surround it by another curly braces.
Hence the Data should beBut I typically prepare the json before and then use function toJSON() before passing to the request. (that's why I forgot about this already). To do so, create a new map/list as your data should be. Your json is a single level map type with key-value. So it should beCode: Select all
{'{"entity_id":"light.rgbw_1"}'}
Then use {js} in the Data field. IMHO, this is the recommend good practice (in Automagic) to pass JSON to the http request. toJSON() will ensure any special character will be escaped properly.Code: Select all
object = newMapFromValues("entity_id", "light.rgbw_1"); js = toJSON(object);