HTTP Request (POST, PUT) action

Elenkhos

Member
I've found the HTTP Request GET action extremely useful but unfortunately HTTP Request lacks POST and PUT methods that many services use. I hope @MacroDroidDev could look if it wouldn't be too timely to also include these methods as the GET is already coded in MacroDroid. I'm sure I'm not the only user that needs to use Tasker to make these distinct types of HTTP requests. Using Tasker makes macros overly complicated and hard to maintain eventually. Sending variables between the two apps is prone to user errors.

I know you're maintaining MacroDroid on your free time so take your time.
 

Elenkhos

Member
Thanks Pseudocyclic for your suggestion. Unfortunately, RESTask for Tasker is too old plugin to support modern authentication methods (for example Bearer) that are needed in the services.

I have also tested HTTP Request apps (like HTTP Request Shortcuts) but I haven't found a way to pass variables to them so they're no use 😟
 
Last edited:

tanutanu

Member
Elenkhos,

Try plugins not only RESTask but HTTP Shortcuts, ParseTask and wget on Termux.
IFTTT is another good option. It accepts GET string, then POST by webhook.
 

Elenkhos

Member
Unfortunately, I can't get any of the suggested plugins to work (tested with LIFX HTTP API). HTTP Request Shortcuts seems a nice and well-built app but the variables from MacroDroid doesn't seem to be send to it even though I followed the instructions on the developer Github page. It could be just an issue with MacroDroid.

And, in fact, I'm trying to move away from IFTTT as I don't like the design which is targeted for beginners and not taking the needs of power users into consideration (even with the premium subscription). In addition, using the IFTTT as a middleman isn't much better than using Tasker. The whole point being to simplify my macros because maintaining them has become quite hard as their number has grown to hundreds 😅
 

tanutanu

Member
Alternative, write shell script(or any language whatever you want) to execute wget command on Termux console. You can pass/receive any variables as argument:)
 

Biazzotto

New member
Alternative, write shell script(or any language whatever you want) to execute wget command on Termux console. You can pass/receive any variables as argument:)
How to do that?
"Termux:Tasker" plugin doesn't work because of lack of permission on MacroDroid App to "Run commands in Termux environment".
 
Last edited:

tanutanu

Member
Try plugin version 4.0 or below. You can set Locale/Tasker Plugin Action, and choose Termux:Tasker plugin.
On the next dialog, set a script name which you wrote in ~/.termux/tasker/ path, and %arg as Tasker argument style to send a variable you want to pass.
In your script, write to stdout as a return value to send back to your Macrodroid macro.
 

nwaan

New member
I got RESTask for Tasker to work with macrodroid but it was slow and caused a pop up that said "Macrodroid isn't responding". Choosing wait, let the macro complete.

I also tried HTTP Shortcuts and was able to create an HTTP Post command. Running this plugin from macrodroid did not work. However, I was able to use HTTP Shortcuts to make a shortcut icon that can be added to the homescreen. It did work to have Macrodroid access the HTTP Shortcut by using the macrodroid "Launch Shortcut" action.
 

sbstratos79

New member
In case you still haven't found a solution. You can pass variables to HTTP shortcuts like this:

Make sure the variable you're using is static.

Once you've created the shortcut in the app, open the context menu in the app by long pressing the shortcut, select Show Info. Copy the deep link.
In your macro, add an action for Send Intent. Target should be activity and paste the deep link inside the Data field. Append

?variable_name_in_http_shortcuts_app=[lv=macrodroid_variable]

Or you can add the macrodroid variable to the field by pressing ... Button and selecting it from there. Of course you can add any other value as well.

The final link should be something like:


http-shortcuts://deep-link/f5cdd52a-8baf-4d20-ab4e-e367d167f861?h_variable=[lv=m_variable]
 

nwaan

New member
Using HTTP Shortcuts, I finally figured out the right JSON command to set the brightness level on my Kasa HS220 smart dimmer switch. You need to have a current token, UUID, and device ID for the Kasa switch.

First I created a variable in HTTP Shortcuts by clicking on the 3 dots and using variables to create a static variable (constant) and gave in the name KasaLevel. I put a value of 10 in for the level and checked the URL encode option. I also created variables for my KasaToken, KasaTermID, and KasaDevID and put my current token, UUID, and device ID for the switch into those variables also with the URL encode option checked.

1) I then created a shortcut with the text below as the basic request settings. The variables for {KasaToken} and {KasaTermID} need to be included by clicking on the {} in the upper right corner.

https://use1-wap.tplinkcloud.com/?token={KasaToken}&appName=Kasa_Android&termID={KasaTermID}&appVer=1.4.4.607&ospf=Android+6.0.1&netType=wifi&locale=en_US HTTP/1.1

2) I then added a request header with header of Content-Type and value of application/json.

3) And finally I set the request body/parameters with custom text and a request body as shown below with the variables for {KasaDevID} and {KasaLevel} included by clicking on the {} in the upper right corner.

{
"method":"passthrough",
"params":{
"deviceId":"{KasaDevID}",
"requestData":{
"system":{
"set_relay_state":{
"state":1
}
},
"smartlife.iot.dimmer":{
"set_brightness":{
"brightness":{KasaLevel}
}
}
}
}
}

Once the HTTP shortcut is created, a long click on the title pops up a new menu and choosing "Show Info" gets a Deep-Linking URL. The URL can be used in macrodroid with a send intent as described above.

For me, in macrodroid, I created a macro with a local variable called "KasaLevel" and gave it a value. Then I inserted a "Send Intent" action with the Target set as "Activity" and Data as the URL copied from the HTTP Shortcut Deep-Linking URL, followed by ?KasaLevel=[lv=KasaLevel] with the last part inserted via the "..." button and choosing the local variable I named KasaLevel.
 

Elenkhos

Member
In case you still haven't found a solution. You can pass variables to HTTP shortcuts like this:

Make sure the variable you're using is static.

Once you've created the shortcut in the app, open the context menu in the app by long pressing the shortcut, select Show Info. Copy the deep link.
In your macro, add an action for Send Intent. Target should be activity and paste the deep link inside the Data field. Append

?variable_name_in_http_shortcuts_app=[lv=macrodroid_variable]

Or you can add the macrodroid variable to the field by pressing ... Button and selecting it from there. Of course you can add any other value as well.

The final link should be something like:


http-shortcuts://deep-link/f5cdd52a-8baf-4d20-ab4e-e367d167f861?h_variable=[lv=m_variable]
Thanks! I can confirm this works.
 
Top