Web-hook Response Not Working (Product Device)

electron
Tags: #<Tag:0x00007f1cae609ab0>

#1

I’m attempting to get a response from my webhook and it doesn’t seem to be responding. The published event triggers the webhook and I can see it is successful in the console.

Here is the device-side code:

void gcp_cloud_time_zone_handler(const char *event, const char *data) {
  // Handle the integration response
  arl_debug("event: %s, data: %s", event, data);
}

void gcp_cloud_init(void)
{
    arl_debug("Initializing GCP web-hooks...");
  // Subscribe to the integration response event
  Particle.subscribe(System.deviceID() + "/hook-response/time_zone/", gcp_cloud_time_zone_handler, MY_DEVICES);

}

int gcp_cloud_get_timezone(void)
{
    sprintf(m_msg,"{\"location\":\"33.570297,-117.723793\",\"timestamp\":\"1557790143\"}");
    arl_debug("publish: time_zone: %s", m_msg);
    Particle.publish("time_zone", m_msg, PRIVATE);
}

Here is the successful event as seen in the Particle IO console:

{
  "name": "time_zone",
  "data": "{\"location\":\"33.570297,-117.723793\",\"timestamp\":\"1557790143\"}",
  "ttl": 60,
  "published_at": "2019-05-14T23:31:33.660Z",
  "coreid": "2f002a000847373334363431",
  "userid": "",
  "version": 4,
  "public": false,
  "productID": 8295
}

Here is the successful response on the Particle IO console from the Google Time Zone API:

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Tue, 14 May 2019 22:38:26 GMT
Expires: Wed, 15 May 2019 22:38:26 GMT
Access-Control-Allow-Origin: *
Server: mafe
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Server-Timing: gfet4t7; dur=88
Cache-Control: public, max-age=86400
Age: 3187
Alt-Svc: quic=":443"; ma=2592000; v="46,44,43,39"
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

{
   "dstOffset" : 3600,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Daylight Time"
}

Output of my device console with no response:

[23:44:01:321] Connected to cloud.
[23:44:07:461] lat=33.570297 lon=-117.723793 alt=0 uncertainty=4171
[23:44:07:461] Initializing GCP web-hooks...
[23:44:17:722] publish: time_zone: {"location":"33.570297,-117.723793","timestamp":"1557790143"}type or paste code here

I’m sure I’m doing something wrong I just can’t see it.

Thanks.


#2

Are you sure your subscribe filter is correct?
How is the response event called in console?

I’m not convinced that you should prepend the device ID and I’d also drop the final /.
So try this instead

Particle.subscribe("hook-response/time_zone", gcp_cloud_time_zone_handler, MY_DEVICES);

But if you are doing this from a product device (which would be a necessary info in the opening post) then entirely different rules apply.


#3

Yes, it is a product device. I’ve followed the code example shown in this document: https://docs.particle.io/tutorials/device-cloud/webhooks/#product-webhook-responses.

Also my code is essentially cut-and-paste from the “code example” in the console when I defined it.

I haven’t had a chance to try your suggestions, but I will tomorrow.


#4

I have added the (Product Device) clarification to the topic title.

@rickkas7 knows more about the additional prerequisites to route webhook responses back to the device.


#5

Is this checkbox checked in your webhook? Since your subscribe has MY_DEVICES (recommended), the checkbox must also be checked.


#6

Yes, the checkbox is checked. I’ve also tried @ScruffR suggestions of removing the “/” after the “time_zone” and removing the Device ID. It still did not respond. So I’ve put the code back to the suggested in the console. Also, the console response is the following:

{{PARTICLE_DEVICE_ID}}/hook-response/{{PARTICLE_EVENT_NAME}}

So my subscription code is back to this:

void gcp_cloud_init(void)
{
    arl_debug("Initializing GCP web-hooks...");
  // Subscribe to the integration response event
  Particle.subscribe(System.deviceID() + "/hook-response/time_zone/", gcp_cloud_time_zone_handler, MY_DEVICES);
}