Passing External Data To Workflow Through Webhook

Hello

I am having issues passing data through a webhook to my workflow. I have multi-field data that the workflow will need to use to operate such as 3 -4 parameters.

If this is achievable through the use of webhook, I will like to know the format for the https request.

Thank you

Hey @ebuka,

I can type up a good example for you. However, I have two questions for you:

  1. What issues are you having?
  2. What are you doing with the webhook data? Reporting State, Creating an Event, etc.

Hello @anaptfox

I will like to update an existing data table with new figures or thresholds for existing devices. I have my devices listed in a table along with some set points for which an event will be triggered.

An example is to pass a new temperature and humidity threshold value to the workflow, which will eventually update the corresponding row/column in a table.

Hello @anaptrox

Please I was wondering if my response was clear enough and if you have had some time to look at this. I think an example will be sufficient.

Thank you

Yes! Your explanation was great. I’m actually preparing your example right now.

@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:

  1. Configuring an HTTP Post request.
  2. Losant Webhook.
  3. Setting an application/json Content-Type.
  4. This is the data we want to send to the Workflow.
  5. Here is the response of the Webhook. You can have Custom Replies.

Here is the most simple workflow we can build:

  1. Webhook Trigger
  2. Table: Update Node
  3. 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.

  1. The Data Table to update
  2. A Data Table Query.
  3. 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.

2 Likes

Thanks so much @anaptfox

I was able to get through with the guide you provided. Really appreciate your help with this.