Webhook with variable URL and JSON payload

I currently have a GET webhook with an URL that contains an "extension" which I pass to the webhook when triggering it:

https://some url/{{URL_PATH}}

This works well when I pass "{\"URL_PATH\":\"%s/config\"}" as the data to the publish triggering the webhook.

I would like to now create a POST webhook where a similar URL_PATH needs to be passed along with a JSON payload which is pre-constructed in my code. I can't seem to figure out how to create the full JSON string to send to the webhook where it splits the URL_PATH as above and the JSON payload to send. I have tried the following without luck.

"{\"URL_PATH\":\"%s/config\", \"payload": {*valid JSON payload*}}"

Does anyone have experience they could bring to bear here?

hey Paul, is your issue on the webhook mustache or in the firmware?

@gusgonnet, on both. I need to a) understand how to setup the POST webhook and b) understand how to format the outgoing publish to correctly "populate" the webhook URL and body to successfully hit the target site.

Hey @peekay123 — this is a great use case for Logic! Have you explored the feature at all?

@Dan-Kouba, I would rather not use it at this time, if possible.

I would start here:

From there I interpret that if your publish is this:

"{"URL_PATH":"%s/config", "payload": {valid JSON payload}}"

you can access its values with {{{URL_PATH}}} and {{{payload}}} on the webhook side.

One thing I noticed, might be your copy paste though, is that payload value MUST be surrounded by quotes, must be a string:

"{"URL_PATH":"%s/config", "payload": "{valid JSON payload}"}"

Are you planning on using JSON writer to create that string to be published?

I have the distinct impression that manually publishing the webhook data via CLI is the problem.

I'm coming to town soon so I'll make sure I bring a device with me :clown_face:

So the problem ended up being how I was publishing a test using CLI. Formatting the correct JSON text was incorrect. Instead, I coded the test publish data in a simple web application and the webhook correctly fired with the {{{URL_PATH}}} and {{{payload}}} working as expected. Thanks @gusgonnet for your help!

Darn, that was tricky. Happy to hear you sorted it out.

1 Like