responseTopic accept arguments?

I can pass argument(s) put into the data of a Publish event formatted in JSON:

  String publishString = "{\"productFamily\":\"projectName\",\"my-city\":\"Chicago\",\"my-state\":\"IL\"}";
  Particle.publish("testing", publishString, 60, PRIVATE); //

and use the ‘variables’ in the web hook:

{
	"event": "webhookName",
	"url": "http://api.wunderground.com/api/getYourOwnAPI/astronomy/q/{{my-state}}/{{my-city}}.json",  
	"requestType": "POST",
	"headers": null,
	"query": null,
	"responseTemplate": "{{#sun_phase}}{{sunrise.hour}}~{{sunrise.minute}}~{{sunset.hour}}~{{sunset.minute}}~{{#moon_phase}}{{current_time.hour}}~{{current_time.minute}}{{/moon_phase}}~{{/sun_phase}}",
	"responseTopic": "{{productFamily}}_sun_time",
	"json": null,
	"auth": null,
	"coreid": null,
	"deviceid": null,
	"mydevices": true
}

both my-state and my-city, which you can see are placed in the URL, are passed but the other variable, productFamily will not. If I use (which I do very often) {{PARTICLE_DEVICE_ID}} it works fine.

Can someone tell me if I can/cannot pass a variable from the JSON formatted data to responseTopic? It seems not to work for me, or I am using an incorrect method.

This feature would be nice to have :+1:
And I hope Particle can tell how it’s done, if it’s already there or implement it in near future if it isn’t.

I guess the reason why it’s not working as is, comes from the fact, that productFamily is only part of the request against the Particle cloud but not part of the response created by the target server (which is further “decorated” with the standard fields (e.g. PARTICLE_DEVICE_ID) by the Particle cloud before it gets delivered to your device).

The Particle cloud takes all your fields from your request to create the remote request and then drop any not used ones (I think :blush:).
Once it receives the response, that extra info is already gone and only the response content will be fed back into the response template/topic.
I guess there is no real (other than timeout/error check) link between the creation of the remote request and the remote response on the Particle cloud side and hence (currently) no way to have a custom template field jump the gap to end up in the hook response.

To test this theory, you could attempt to create a field collision between request and response by using a field name present in the response in your request already. I guess you’ll not get an error. I’d rather expect that the request will use your request-value for that field and the response will contain the value provided by the responding server.
But if you use a field present in the remote response for responseTopic, I’d think that’ll work as expected.

1 Like