HTTP_shortcuts to Macrodroid

jmlat

Member
may be it does'nt works for POST.....
no, i tried with GET. of course i get an error and script on error executes.
then in script on error I toast "erreur"and setResul("erreur") but again i can see popup but no result in error MD variable !
so POST or GET is not the problem...
 

jmlat

Member
well...
I re-write my HTTP shortcut, without any differences but a new one...and then it works !
I have no idea why !!!
maybe shortcut must be create after macro, I don't know, it's very strange for me...
maybe someone could explain it to me...

Anyway many thanks for all
 

RSF

Well-known member
I couldn't get your HTTP Shortcut to send back the "result" value to MacroDroid either, although the HTTP Shortcut worked fine to send a result back to Tasker (a somewhat similar app to MacroDroid). It seems that there's something fragile and possibly unreliable with the plug-in integration between HTTP Shortcuts and Macrodroid.

If your project now works, and continues to work, great; no need to read further and complicate things...

But if you run into any further issues with HTTP Shortcuts passing a result back to MacroDroid (or for others who might read this thread later and have problems), here's an alternative way to send results from HTTP Shortcuts back to MacroDroid, using intents. It seems to work reliably.
  1. Instead of putting "setResult(response.body);" in the HTTP Shortcuts script, use its sendIntent command instead:
    Screenshot_20231128-110042.png
  2. Then, in MacroDroid, add a trigger to capture that intent, and store the value into a local variable:
    1701198938084.png
  3. And redo the macro as in the attachment, to call your HTTP Shortcut without the "Block next actions until complete" option, instead having a "Wait until trigger" action to do the same thing -- pause the macro until a result is sent back, at which point you can proceed with whatever you want to do (the attached macro just displays the result value, in a popup dialog box).
 

Attachments

  • HTTP_Shortcuts_integration_via_intent.macro
    9 KB · Views: 2
  • Like
Reactions: Vix

Dimlos

Well-known member
I edited it I can assign a response.
Resolving code:305 is another matter.
 

Attachments

  • response.jpg
    response.jpg
    423.7 KB · Views: 7

jmlat

Member
I edited it I can assign a response.
How strange is it !
I edited it several times without succes, and when I rewrote shortcut, it was ok ...
Instead of putting "setResult(response.body);" in the HTTP Shortcuts script, use its sendIntent command instead:
Very interresting: I knew it was possible to use intent in android, but I din't know how do this with MD...it's a first liht to me.
I will probably use it in further macro...
I think some tutorials about MD would be productive for lot of people

thanks to Dimlos and RSF !
 
  • Like
Reactions: RSF

Dm114

Well-known member
How strange is it !
I edited it several times without succes, and when I rewrote shortcut, it was ok ...

Very interresting: I knew it was possible to use intent in android, but I din't know how do this with MD...it's a first liht to me.
I will probably use it in further macro...
I think some tutorials about MD would be productive for lot of people

thanks to Dimlos and RSF !
To begin with, MD Wiki could help many MD beginners to better understand how it works...
 

jmlat

Member
To begin with, MD Wiki could help many MD beginners to better understand how it works...
yes you're rigth. but i use MD for years and already had a look on it.
but i'm newbe with requests and i thought that MD request could be use dirrectly for my project...
and this was not helpfull...
 

jmlat

Member
one more question:
We saw above that we can sent variable from HTTP shortcuts to MD. but can we sent variable from MD to HTTP shortcut ? (for exemple a date or time)
 
  • Like
Reactions: Vix

RSF

Well-known member
can we sent variable from MD to HTTP shortcut ? (for exemple a date or time)
Easiest way is to define a variable in MD matching (with exactly the same name, and type) a variable in HTTP Shortcuts. MD will pass its value into that HTTP Shortcuts variable each time a shortcut is executed. Works for both global and local variables in MD.
 

Vix

Member
Easiest way is to define a variable in MD matching (with exactly the same name, and type) a variable in HTTP Shortcuts. MD will pass its value into that HTTP Shortcuts variable each time a shortcut is executed. Works for both global and local variables in MD.
can you elaborate it?
 

RSF

Well-known member
Sure. In the MacroDroid macro, define a variable (in the example below, "testvar"). The variable can be global or local; both work fine. Then in the HTTP Shortcuts shortcut, access the value using HTTP Shortcuts' getVariable() function, using the exact same name as the variable in MacroDroid.

Here's an Example MD macro, which prompts for a value to send to HTTP Shortcuts, then executes a Shortcut:
1705634491166.png

In the HTTP Shortcuts Shortcut, access the value in the Shortcut's Scripting window (in this example, the value passed from MacroDroid is simply displayed briefly in a popup "toast", but could of course be used in a variety of ways):
1705634594974.png

There's no need to specify anything special in the Execute HTTP Shortcut action to pass the variable; MacroDroid seems to pass all variables automatically.
 
Top