Webhook is ignoring my template

I’m trying to use a webhook to post data to a web service. I’ve followed the documentation and the webhook fires but it always sends as application/x-www-form-urlencoded and it ignores my json template. I also included the ‘noDefaults’ flag but it ignores that too. My Webhook is defined as follows:

{  
   "eventName":"myEventName2",
   "url":"http://requestb.in/16bg3jw1",
   "requestType":"POST",
   "json":{  
      "statusCode":"{{s}}",
      "statusDescription":"{{d}}",
      "value":"{{v}}"
   },
   "mydevices":true,
   "noDefaults":true
}

If I then use the CLI as follows:
particle publish myEventName2 "{ \"s\":500, \"d\":\"Test\", \"v\":2 }"

The webhook fires but it sends the following in the body of the request:
event=myEventName2&data=%7B%20%22s%22%3A500%2C%20%22d%22%3A%22Test%22%2C%20%22v%22%3A2%20%7D&published_at=2015-12-18T15%3A07%3A44.367Z&coreid=001_55d88081e51d46a539374a9b_1450451264366_2247919
I want the webhook to post my json to the web service, replacing the values from my ‘data’ string. I’m certain I’m overlooking something obvious - can anyone see what it is?

Thanks in advance!

This is the output from 'particle webhook create':

Using settings from the file .json
Sending webhook request { uri: 'https://api.particle.io/v1/webhooks',
method: 'POST',
json:
{ event: 'myEventName2',
url: 'http://requestb.in/16bg3jw1',
deviceid: undefined,
requestType: 'POST',
mydevices: true },
headers: { Authorization: 'Bearer blahblah' } }
Successfully created webhook with ID some_id

I am hitting the exact same issue, and I’ve been banging my head for hours now. I made a small update to the JSON body of my existing webhooks, which have been working fine for months now, and I’m getting the exactly same broken content type. I’ve tried adding a custom Content-Type: application/json header to force it, but that is ignored as well.

The same webhooks in my production environment that I haven’t updated continue to work fine.

1 Like

Same issue here!

I have created a web hook using the following .json:

"eventName": "TMeasured",
"url": "http://requestb.in/1dxs45o1",
"requestType": "POST",
"json": {
    "message": "prova"
},
"mydevices": true,
"noDefaults": true

}

but when I do

particle webhook create xxx.json

it returns:

    Sending webhook request  { uri: 'https://api.particle.io/v1/webhooks',
  method: 'POST',
  json:
   { event: 'TMeasured',
     url: 'http://requestb.in/1dxs45o1',
     deviceid: undefined,
     requestType: 'POST',
     mydevices: true },....

and inspecting RequestBin the post is sent as application/x-www-form-urlencoded instead of application/json!

Thank God I'm not the only one.

I just posted this new discussion with the exact same issue. I'm pulling my hair out.

Has anyone from Particle looked into this, or has anyone found a solution? Looks like at this point I have to refactor my API to consume form encoded events or scrap webhooks altogether.

Check here: Webhook responseTemplate not working correctly?

An update for particle-cli was recently posted so do npm update -g particle-cli and try recreating your webhooks to see if it fixes your issue.

Beautiful. All fixed. Thank you!

1 Like