@ebuka,
Let’s say, for example, you had a Data Table that looked like this:
Here, I’m going to walk through receiving a Webhook (that includes HTTP POST data) and using those values to update a Data Table with the same structure you see above.
Here is the data we can send to the Webhook:
{
“deviceId”: “5eb16e1d1ac8cb000623fb1c”,
“temperature_threshold”: 94,
“humidity_threshold”: 60
}
We can use Postman to make the request:
- Configuring an HTTP Post request.
- Losant Webhook.
- Setting an
application/json
Content-Type.
- This is the data we want to send to the Workflow.
- Here is the response of the Webhook. You can have Custom Replies.
Here is the most simple workflow we can build:
- Webhook Trigger
- Table: Update Node
- Debug Node
When the workflow triggers, it creates the following payload:
{
...
"data": {
"body": {
"humidity_threshold": 60,
"temperature_threshold": 94,
"deviceId": "5eb16e1d1ac8cb000623fb1c"
},
"query": {},
"headers": {
...
},
"method": "post",
"path": "/"
},
"time": "2020-05-05T14:29:42.764Z"
}
All of the values are at data.body
because they were in the body of the HTTP request.
Now that our values are on the payload, we can use them in our Table: Update Row Node.
- The Data Table to update
- A Data Table Query.
- You can optionally insert if the row doesn’t exist.
Here we are using the following query: deviceId === "{{data.body.deviceId}}"
.
This allows us to find the row in the Data Table where the “deviceId” column is equal to the current value at {{data.body.deviceId}}
.
Then, we can use the other values to update the found row:
Now, if you trigger what we have above, it will update the Data Table values when the Webhook is requested.
You can even take this workflow further by checking to see if the row existed and perform different actions based on the result:
I’ve made the workflow above available for you to download here.