Why is my webhook request running several times with one call?

I’ve successfully set up a webhook (with the help of @peekay123 and others in the community) and am sending data to my website which send email and sms messages based on the request. Every time I send a request, though, the script is run 5-6 times (which means 5-6 duplicate email/sms messages). For the life of me, I can’t figure out what’s happening.

Here’s my json file for the webhook.

{
"event": "venus",
"url": "http://mysite.com/notify.php",
"requestType": "GET",
"query": {      
    "id":"{{SPARK_EVENT_VALUE}}",
    "location":"{{SPARK_CORE_ID}}"
},
"mydevices": true
} 

Here’s what subscribe looks like in the terminal after single call:

{"name":"venus","data":"A2","ttl":"60","published_at":"2016-04-29T14:56:33.690Z","core id":"9j12345678901234567890"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.832Z","coreid":"particle-internal"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.848Z","coreid":"particle-internal"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.849Z","coreid":"particle-internal"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.869Z","coreid":"particle-internal"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.874Z","coreid":"particle-internal"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.876Z","coreid":"particle-internal"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.878Z","coreid":"particle-internal"}
{"name":"hook-sent/venus","data":"undefined","ttl":"60","published_at":"2016-04-29T14:56:33.881Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"404","ttl":"60","published_at":"2016-04-29T14:56:34.235Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"404","ttl":"60","published_at":"2016-04-29T14:56:34.248Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"SUCCESS","ttl":"60","published_at":"2016-04-29T14:56:35.613Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"SUCCESS","ttl":"60","published_at":"2016-04-29T14:56:35.613Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"SUCCESS","ttl":"60","published_at":"2016-04-29T14:56:35.650Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"SUCCESS","ttl":"60","published_at":"2016-04-29T14:56:35.665Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"SUCCESS","ttl":"60","published_at":"2016-04-29T14:56:35.678Z","coreid":"particle-internal"}
{"name":"hook-response/venus/0","data":"SUCCESS","ttl":"60","published_at":"2016-04-29T14:56:35.744Z","coreid":"particle-internal"}

Any suggestions on how to troubleshoot this? What am I missing?

I’ve also uploaded all the files for the project to github if that’s helpful.

may be related

@stuboo, what I see on the output doesn’t seem to match the code you posted on github. For example, I don’t see where “data” is sent. What are you expecting to be returned from your server?

@peekay123

What are you expecting to be returned from your server?

A simple SUCCESS message.

This is being returned, but way too many times.

They way I read/understand the terminal subscribe is this:

  1. The webhook is called correctly when I push # key in the arduino code.

    {"name":"venus","data":"A2","ttl":"60","published_at":"2016-04-29T14:56:33.690Z","core id":"9j12345678901234567890"}

  2. The API then does something EIGHT times

  3. My website responds (the frist two times with a 404 apparently) then with the SUCCESS message six times.

output doesn't seem to match the code you posted on github

Which part doesn't match?

Thanks,
Ryan

@BulldogLowell Thanks! That sounds like exactly what’s happening. If I have time later today, I’m gonna change my webhook endpoint, create a new webhook, and try again.

@stuboo, the publish() in the github code is sending “String(value)”, and not “data” so the code does not match what the output of the publish is doing.

@BulldogLowell is correct that the problem you are having is related to the webhook issue, especially if you have several deleted iterations of your webhook. You could create a new webhook with a slightly different name which should solve the problem, at least until phantoms are fixed.

sorry, not a problem that I suffer, I just observed others having the issues.

@peekay123 Clearly, I’m not following you regarding the publish() command. String(value) is the data I want to pass.

Particle.publish("venus", String(value), 60, PRIVATE);

Care to write out the statement the way you think it should be written? As it stands, it seems to be passing the data that I want.

I guess the use of String(value) is a bit confising since value already is a string.
You’d usually only use String() to convert a non-string into a string.

@stuboo, as I believe I indicated before, I don’t see how you are passing “data” via your webhook to your server. Your webhook makes no reference to “data”. If you do want to pass “value” via your webhook, you need to format it as a json object.

@peekay123 The “data” is being posted as a GET request to the php script on my sever. I used this tutorial to guide me through the process…

https://docs.particle.io/guide/tools-and-features/webhooks/#lets-make-some-graphs

In the tutorial, they do sent some JSON as a parameter in the request, but that’s because the Librato API requires requests in JSON format. I wrote my script to accept GET requests, so the webhook passes the data along as such via the query parameter and the {{SPARK_EVENT_VALUE}} mustache.

I’m not trying to be obstinate, but the data is actually being passed to my sever and interpreted appropriately. It’s just being sent too many times. I sincerely appreciate your guidance.

@stuboo, I am obviously missing something in how you webhook query is translating to "data":"A2", at least as it is in your repo. Nonetheless, just ignore me as the real issue is with the webhook backend. I’ll just be on my merry way :wink:

We just deployed a fix that should prevent zombie webhooks from happening. :knife:

3 Likes