Debug WebHook Response (JSON)

Hi

I have set up a webhook. The request type is “form” and sends these form fields.

{
  "device_id": "{{SPARK_CORE_ID}}",
  "temp": "{{t}}"
}

I have set the headers to include:

{
  "Content-Type": "application/json",
  "Accept": "application/json"
}

The response is to call another third party webhook and this is indicating it receives the following payload:

event=xxxxx&data=%7B%22m%22%3A%3A%2265%22%7D&published_at=2017-01-04T10%3A42%3A33.940Z&coreid=2b004xxxxxxxxx373738&temp=65&device_id=2b00xxxxxxxx8

This does not look like json and in fact the callback fails with “Couldn’t parse payload into json, leaving as string”

The Particle console does a great job of providing e.g. the data that initiated the particle webhook call, and much of the data sent to the request webhook url, but it does not show the payload (i.e. is it being sent as json?).

Question 1- any suggestions on how to capture exactly what is being sent to the request URL (other than create a dummy proxy url to send to)

Question 2 - Given the post sample above and the request headers set to json, should this guarantee the post data is being sent as json?

Thank you in advance.

If you’re using “form” in your webhook definition, the data is sent as application/x-www-form-urlencoded data, not as JSON. You need to use the key “json” instead of “form” to send the body as JSON.

This document has some more tips that may be helpful, including debugging the payload data using request bin:

2 Likes

Of course, select JSON!. I copied an original json based webhook created using the CLI, prior to the Web IDE offering. When this original code is viewed in the IDE it indicates the request type is FORM. Thank you for the prompt response.