Execute piston externally (via webhook) with arguments?


#1

This feels like the wrong place to ask this, because it’s not about design help, but more of a general question. I’m having trouble figuring out how to pass arguments to a piston when executing it via webhook?

Are the arguments passed as part of the URL? Like:
https://[piston url]?arg1="blah"&arg2="blahblah"

Or is it passed in the body as a JSON object?

EDIT:
I found this comment by WCmore:

So it looks like it’s in the URL. But I guess my other question is…

I have a piston who takes in a list of parameters via a JSON object.

So in the receiving piston, it looks like this:

$args.args.message
$args.args.messagetypes

WIth the sending piston looking like this:
[string] args = {"message":"this is a test","messagetypes":"echo,push"}

So I just pas the args variable into the piston when I execute it.

I’m trying to figure out how to perform this external execution via webhook?


So my best guess, is that it would be something like this?

https://[piston url]?args={"message":"this is a test"}

I tried this, but it doesn’t work…so I dunno…


#2

Figured it out…was merely a url encoding issue:

https://[piston url]?args={"message":"this is a test"}

Once encoded into this:
https://[piston url]?args=%7B%22message%22%3A%22this+is+a+test%22%7D

It works great!


#3

I would try something like this:

https://api.smartthings.com/api/token/abc123/smartapps/installations/def456/execute/:ghi789:?message=this%20is%20a%20test&messagetype1=echo&messagetype2=push

Alternatively, you can try using ‘+’ instead of ‘%20’:
message=this+is+a+test


#4

I purposely didn’t want to go that route because it makes executing that piston from other pistons a PITA because you have to create a variable for each parameter you want to send, and the name of the variable is the name of the argument that gets sent.

So I chose to go this route instead:

The full JSON body is:

{
    "message":"this is a test",
    "messagetypes":"push,sms,echo",
    "smscontacts":"chad,kaylee",
    "echolocations":"bedroom,kitchen,garage"
}

Now, all I have to do is pass in the JSON object as a single argument. I don’t have to deal with 4 separate variables.

For reference, here’s the greenshot:


#5

For the record, no webCoRE variables are required in my previous post.


#6

If you were executing that piston from another piston, wouldn’t that require having three variables in the piston that is performing the execution? [string] message, [string] messagetype1 and [string] messagetype2?

Unless you are executing pistons from other pistons using the webhook rather than the built in function.


#7

Neither piston needs variables if you use this method:

https://api.smartthings.com/api/token/abc123/smartapps/installations/def456/execute/:ghi789:?message=this+is+a+test&messagetype1=echo&messagetype2=push

(although variables would be helpful if you need the data to linger between executions)


#8

Right, that’s what I was saying. You’re executing pistons from other pistons using their webhook, rather than using the built in “Location > Execute Piston” function.

I suppose that’s something I could consider. However, in some areas, I would lose my ability to wait on piston execution completion. But I’m only using that in one piston so far.


#9

Sorry if I was unclear… All of my examples above are using “Make a GET request” as you have done.


#10

When I execute this piston, I just use “Location > Execute Piston” and then I pass in the JSON string as a variable named “args”.

Example usage:

I hadn’t considered executing the piston via “Make GET Request”. I’ll have to look into converting over to that method instead.

The reason I’m trying to ask about the GET request in this post is because I plan on executing the piston from other projects outside of WebCoRE.


#11

I believe that my single line example should also work with the “Execute piston” command.
(although the args are a separate step when using “Execute piston”)

You threw a curve ball though, because you kept mentioning externally via webhook…
(instead of internally via Execute piston)… LOL