Webhook HTTP Post Request utilization with Webhook Reply and Device State

So far we have established the following on our attempt to connect a webhook capable gateway (we developed a gateway that has a web app that allow for an easy webhook connectivity) with losant:

  1. We create an application in losant
  2. We created a device in the application
  3. We added an an attribute to each data point we wanted to track
  4. A Webhook Trigger was issued, copied and pasted within our gateway as the URL to send the HTTP post request to.
  5. We are not clear on how to set the Device State Node in order to pull values off of the payload and how to report them as state for the attribute we added on the losant device. We followed the instruction you have in your documentation but suspect this can resolve the issue we have (please instruct in detail with respect to the payload described below).

To verify our gateway is attempting to send HTTP request we changed (on our gateway) its endpoint (trigger URL) from the endpoint (HOST URL) losant generated :
https://triggers.losant.com/webhooks/xxxxxxxxxxxxxxxxxxxxxxxxxxxx$

To a pipedream requestBin (traffic inspector) endpoint(HOST URL) generated.

On the pipedream traffic inspector we found our gateway send HTTP requests and they are received as HTTP post requests. Below you can see the headers and Raw body of the request.

Headers:
host: xxxxxxxxxx.x.pipedream.net
accept: application/json
Content-Type: application/json
Content-Length: 831
Connection: keep-alive

Raw Body:
{
“deviceId”: “xxxxxxx_xxx”,
“data”: {
“500”: {
“analog-input:1”: {
“present-value”: [
{
“value”: 26.399999618530273,
“timestamp”: 1553543607126
}
]
},
“analog-input:5”: {
“present-value”: [
{
“value”: 50,
“timestamp”: 1553543607126
}
]
},
“analog-input:4”: {
“present-value”: [
{
“value”: 1.0998377799987793,
“timestamp”: 1553543607126
}
]
},
“analog-input:8”: {
“present-value”: [
{
“value”: 0.00244140625,
“timestamp”: 1553543607126
}
]
},
“analog-input:3”: {
“present-value”: [
{
“value”: 21.5,
“timestamp”: 1553543607126
}
]
},
“analog-input:6”: {
“present-value”: [
{
“value”: 873,
“timestamp”: 1553543607126
}
]
},
“analog-input:7”: {
“present-value”: [
{
“value”: 0.004999999888241291,
“timestamp”: 1553543607126
}
]
},
“analog-input:2”: {
“present-value”: [
{
“value”: 79.5199966430664,
“timestamp”: 1553543607126
}
]
},
“analog-input:9”: {
“present-value”: [
{
“value”: 0,
“timestamp”: 1553543607126
}
]
}
}
},
“type”: “liveData”
}

Once we changed the gateway endpoint (HOST URL) back to the one losant generated for us we were not able to verify the header or raw body on your platform. With the following workflow configuration: Webhook–>Webhook Reply–>Debug we were able to see the above json in the losant debug window.

Questions: In losant workflow we want to set the Webhook Reply and the Device State.

  1. How should the Webhook Reply be set in order to enable the gateway to be read, so far we set the response code template at 200. Should the body reply, reply headers be filled?
  2. How should the Device State Value per each attribute be set with respect to the above json response from the HTTP post request?
  3. Please confirm the unknow connection status of the device is an MQTT connection indicator only that has not been resolved yet.
  4. As you can see the time response in the json above is in UNIX EPOCH how can it be handled in Losant?
  5. If the immediate goal is to have the attributes from our Gateway displayed in the dashboard will the following workflow be sufficient?:
    Webhook (Trigger)–>Webhook Reply (Output)–>Debug (Output) -->Device State (Output)

Please note we tried the following explanations with respect to the above questions with no viable resolutions:
https://docs.losant.com/workflows/outputs/webhook-reply/
https://docs.losant.com/devices/state/

Thank you

1 Like

Hello @tirosh_gutte!

Glad to hear you’ve successfully implemented the Webhook Trigger, and have data coming in. Let’s dive in to your questions :grinning:

  1. You will only need to configure your Webhook Reply further if you would like a response to be sent back. This is useful if your use case requires data to be sent back to the device, but is not required. In your case it sounds like your current configuration is meeting your requirements. There is more documentation on the Webhook Reply Node here and here.

  2. The Device State Node would be configured as such for your payload: {{data.body.data.[500].[analog-input:4].present-value.[0].value}}, which would look like this in the node:
    53%20AM

  3. Correct! The connection status is for MQTT, so you should not expect a change with a Webhook.

  4. The timestamp attached to the payload will be handled by Losant, we support the UNIX timestamp. To set the state time with the timestamp from your payload, you will only have to change your Device State configuration to look like this:
    50%20AM

  5. Yes, those four nodes are all you will need to be able to dashboard your data! :partying_face:

Let me know how I can help further!
Julia