I now know that hook-response events may undergo several retries to get to my device and if I have two webhook calls within 20 seconds it is possible for the hook-responses to arrive at my device in any order. When my handler on the device receives hook-response data I’d like it to be able to determine which webhook invocation it corresponds to. (This is a simplified example and the idea of creating two identical webhooks with different names will not work in production for me.)
My thought on how to do this is to include a different random string in each webhook call I make. I have not found a good way to include just that random string in my webhook response. (I have no control over the remote system in production so I can’t pass this value through that service.)
My simple example below is asking a remote system if a particular personNumber is authorized. The service returns an allow/disallow in JSON.
Example published event data to webhook:
{
"personNumber":123,
"txdID":454678,
}
The server might return
{
"result":"allow"
}
My webhook response Template would be:
{{PARTICLE_EVENT_VALUE}}
result: {{result}}
With this I could find the txnID and know that a response was for a specific webhook invocation. However, I have to return all of the event data in the response. I was hoping to use mustache code to trim this down. This is what I tried but it does not work.
{{#PARTICLE_EVENT_VALUE}}
txnID: {{txnID}}
{{/PARTICLE_EVENT_VALUE}}
result: {{result}}
I think this fails because PARTICLE_EVENT_VALUE is not a JSON list. But perhaps there is some subtlety here that I don’t understand? Or another way to parse the event value JSON in the response template? I am not a master of mustache code.
(The actual response templates that I use generate formatted data that is more easily parsable on the device, but this example is pared down to just show the issue I’m trying to address. So thanks for thinking about ways to format the response better, but that isn’t the issue here.)
