Webhook frustration

I’ve read the documentation about webhooks about 50 times. I created a very simple webhook and called it by name via Spark.publish(), but for the life of me, I can’t get it to work. Are there any other guides that I might look at for assistance? This is terrible frustrating for an experienced Electric Imp developer who’s trying to take an objective look at Particle.

If you post the code you are using it helps others assist you. All we know is you are having trouble with a webhook and that’s it.

What’s the best way to post code?

Lemme try this:

{
"event": "grovestreams",
"url": "http://grovestreams.com/api/feed?compid=mhgd&api_key=********&fred=17.17",
"requestType": "PUT",
"headers": {
      "Host":"grovestreams.com",
      "X-Forwarded-For": "abcde"
 },
"mydevices": true,
"noDefaults": true
}

I called it with

Spark.publish("grovestreams");

Is it required/advisable to have a Spark.subscribe() to accept any response?

Yikes. I need to learn to post earlier in the process, because it somehow clears my mind and I can see what I’m doing wrong. With a plethora of API keys floating around for various reasons, I had copy-pasted the wrong one. I am successfully posting data.

Since I’ve started this, I’m wondering how I best add something like A1=72.3&AI2=45&AI3=77.1&DI1=1&DI2=0 dynamically to my URL. I’m a bit unclear as to how I best pass up to 12 inputs to Grovestreams via the webhook.

Thanks!

1 Like

Not sure how you miss this:
https://docs.particle.io/guide/tools-and-features/webhooks/#query

Put it in a string then publish the string. If they take JAON data I think that’s the best route.

PS: Spark.whatever() is being deprecated. I would switch to Particle.whatever() now to avoid future issues.

@kennethlimcp, I did see that documentation, but it was/is unclear to me as to how I best pass the data from the Photon to the web hook and reference those values in the context of the query. I’ll do some more testing.

@LukeUSMC, thanks for the advice. I will switch to Particle.whatever(), but had fallen back to the Spark.whatever() in a futile attempt to get it working. WRT the string, I’m trying to decide if I simply want to build a string and pass it or if I should use the query capability. Grovestreams does accept JSON, I believe, so I may look more in that direction.

Hi @ctmorrison,

I’m glad you got it working! Sorry about the frustrating experience initially, and also welcome to the forums! We’re happy to rubber duck anytime. :slight_smile:

Thanks,
David

You’ve probably found this already, but you can use this to pass data from the Photon as query parameters:

https://docs.particle.io/guide/tools-and-features/webhooks/#custom-template-variables

Actually, since you mention Grovestreams accepts JSON, you may be able to use that example as-is.

Hi @Dave,

I do believe the documentation in the area of webhooks could use a little more detail and examples relative to the data passed via the Particle.publish() call. As I understand it, it’s an optional string. If a user wants to pass structured data to reference in the webhook, then format it as a JSON array. The elements (?) are subsequently referenced in the webhook by enclosing them in double curly brackets (ex. {{input1}} ). I guess I don’t understand how to reference the data parameter if you want it in its entirety. Yes, I may be overlooking what’s obvious to others. However, as a newbie, I see things differently and the community may benefit from the naive perspective.

Thanks – I now feel officially welcome!
Tom

Hi @ctmorrison,

Good question! There are four default values available for templating:

{
    "event":  "{{SPARK_EVENT_NAME}}",
    "data": "{{SPARK_EVENT_VALUE}}",
    "published_at": "{{SPARK_PUBLISHED_AT}}",
    "coreid": "{{SPARK_CORE_ID}}"
}

If you wanted to reference the event contents value in its entirety you would use “{{SPARK_EVENT_VALUE}}”. More info on that is available here: https://docs.particle.io/guide/tools-and-features/webhooks/#templates

Feedback is always welcome! I’ll keep trying to improve the docs for webhooks, thanks for posting! :slight_smile:

Thanks,
David

Hi Dave,

The guide is very helpful and well-written, but it would be lovely if you could add at least a sentence before that section stating that those are all the magic variables we have access to. Since it is a guide but also a reference, bits like that would make it more helpful as the latter. That would also motivate the “custom template variables” section that follows.

Thanks!

1 Like

Hi @Dave,

I agree with @indraastra’s comments about the helpful and well-written nature of the guides. I wasn’t meaning to be critical, other than perhaps constructively critical when I indicated the need for a more complete explanation of the Templating capability. As I now go back through the guide, it seems rather obvious to me how it works. However, I struggled (perhaps I’m just dense) with the concept of how structured data could be passed and where all it could be referenced in the webhook.

As I often tell new hires, they see things differently until they get indoctrinated, at which point in time they have a new context for their perspective. It’s during the initial period that they can help us understand those things that just aren’t intuitive to the newbie.

So far, I’m really liking what I see with Particle!

Thanks,
Tom

2 Likes

Hey all!

Totally agree, it’s easy to forget how hard it was to learn something after you’ve learned it. :slight_smile: So we try to pay close attention to this kind of feedback. It’s sounding more and more like we should add a reference doc page for webhooks in addition to the guide, and I’ll leave myself a task to add a clarifying sentence there. :slight_smile:

Thanks!
David

1 Like

So…publishing data is working very well. However, I created another webhook to call a PHP script. The publish is firing and calling the PHP script as expected and I see the hook-response in the Dashboard with the expected JSON data I’ve structured. Unfortunately, I have subscribed to that webhook and specified function is not being called. Thoughts?

Here’s the subscription call:

Particle.subscribe("hook-response/testhook",doNothing);

Here’s the publish call:

Particle.publish("testhook");

…and here’s the line from Dashboard:

{"data":"{\"fred\":\"martha\"} ","ttl":"60","published_at":"2015-10-26T17:24:57.042Z","coreid":"\u0000]\u001cR\u001c","name":"hook-response/testhook/0"}

However, in doNothing() I’m incrementing a global variable that is not getting incremented.

I hope I’m just making a newbie error.

@ctmorrison, do you possibly have two webhooks of the same name? Creating a webhook with the same name as one that already exists does NOT overwrite it. Instead, it create a new webhook, same name but with a different ID. @Dave, if anything, THIS is something that should be looked at :wink:

1 Like

Totally! I created an issue for this in the CLI to warn if that is happening :slight_smile:

Thanks!
David

1 Like

No…I created a new webhook and only created it once. I had experienced the multiple webhook thingie when I was trying to get publish work initially (I actually like that “feature”). However, this is a new one and there’s only one.

Question – due to coding mistakes on my part, I had lots of errors when I was first trying to get webhook publishing working. Is it possible I need to reset something in my account in order to accept webhook responses?

@ctmorrison, nope. With all the stuff I tested with webhooks, I would have broken the servers, not just my account! However, you may want to make your subscribe (using MY_DEVICES) and publishes (using PRIVATE) private so you don’t accidentally get hit by a public event. :smile:

2 Likes