SPARK_CORE_ID in webhook responseTopic

I’m trying to get my devices to only subscribe to a webhook if it’s relevant to them. I have a number of devices controlling lights around my home, and want to push updated schedules to them when I make changes to them. At the moment, if I save the schedules for one device, all devices receive the updates, and have to trawl through to find the data relevant to them (by deviceID).
I’ve been reading through a number of topics here, and especially this one: Subscribe to a Webhook response triggered by a specific device, but if I implement {{SPARK_CORE_ID}} in the responseTopic then it is evaluated to an empty string. I can see that the value is evaluated in the query section, as the data returned is filtered down to only one device.
Here’s my webhook json (I’ve added the last two keys in an attempt for that to kick something, json and auth could probably be removed too).

        "event": "device_schedules_hook",
        "url": "[MY API]",
        "requestType": "GET",
        "json": null,
        "auth": null,
        "responseTopic": "device_schedules_{{SPARK_CORE_ID}}",
        "noDefaults": true,
        "headers": {    "Content-Type":"application/json",
                        "Tokencode":"[MY TOKEN]"},
        "query": {      "unixtime":"1",

When subscribing to events, I can see that the response is posted to hook-response/device_schedules_ (i.e. {{SPARK_CORE_ID}} is evaluated to empty string. Removing the responseTopic makes the response go back to hook-response/device_schedules_hook.

Please would you help me out, I’ve generated and destroyed dozens of hooks trying to make this work! Really feels like something in the background is buggy, and/or has changed since the last good advice was written up here.

Thanks in advance,

How are you making those updates?

It’s not clear why you are using a webhook. If you want to send something to only one device, you could publish a update_schedule/DEVICE_ID event and have each device subscribe with its own id.

Thanks @jvanier!

My data is currently around 1500 characters, so will have to chunk down the data myself. Was keen to use built-in functionality wherever possible, but may give your idea a go and send each updated schedule one record at a time.
Either way, I’m very sure the {{SPARK_CORE_ID}} should be getting evaluated in the responseTopic.


i did it a little different:

I set up one of the hooks like this:

	"event": "current_weather",
	"url": "{{myState}}/{{myCity}}.json",
	"requestType": "POST",
	"headers": null,
	"query": null,
	"responseTemplate": "{{#response}}{{#current_observation}}{{#estimated}}{{weather}}~{{temp_f}}~{{relative_humidity}}~{{wind_dir}}~{{wind_gust_mph}}~{{dewpoint_f}}~{{/estimated}}{{/current_observation}}{{/response}}",
	"responseTopic": "{{SPARK_CORE_ID}}_current_weather",
	"json": null,
	"auth": null,
	"mydevices": true

calling it like this:

Particle.publish("current_weather", publishString, 60, PRIVATE);

and handle (three different ones, as you can see) like this:

void webhookHandler(const char *event, const char *data)
  if (strstr(event, "myname_gmail/0"))
    gotGmailFeed(event, data);
  else if(strstr(event, "current_weather"))
    gotWeather(event, data);
  else if (strstr(event, "sun_time"))
    gotSunTime(event, data);

using this in setup():

  String deviceID = System.deviceID();
  Particle.subscribe(responseTopic, webhookHandler, MY_DEVICES);

does that help?

Thanks all, had to take a step away from this but am going to have another go over Easter!

I am having the same problem. I have found that:

   "responseTopic": "xxxx_{{SPARK_CORE_ID}}",
   "noDefaults": true,

does not work. (responseTopic is xxxx_) However:

   "responseTopic": "xxxx_{{SPARK_CORE_ID}}",
   "noDefaults": false,

does work. The core id is appended to the response topic.

This might be ok for you, but I need to set noDefaults to false for other reasons, so I am trying to pass data to the webhook and cannot get this to work:

   "responseTopic": "xxxx_{{myDeviceID}}",
   "noDefaults": true, //(or false)

My device code looks like this:

String myDeviceID = System.deviceID();
String dataString = "{\"myDeviceID\":\"" + myDeviceID + "\"}";

When I try this, the responseTopic does not get the device Id appended.

Is it possible to use templates in the responseTopic field??? I can’t get this to work.