Advanced Action Flows – Part 3. Sending information to an external source (URL)

In this example, we are sending some JSON content to a third party endpoint, when a geofence enter event is triggered. Whenever there is an enter event, we are going to pass the name of the geofence and the Visitor ID of that device that triggered it to the defined endpoint.

For this tutorial, we are going to use a free, open online service called Webhook Tester, https://webhook.site/. The service allows you to create your own custom URL with one click  that you can use to easily test webhooks and other types of HTTP requests.

Pre-requisite:

  1. Create Geofences
  2. Install Management app or your own app with the Proximi.io SDK integrated
  3. Open Webhook Tester to get your own test URL

Step 1 : Import the following piece of code into the action flow clipboard from top right corner.

[{"id":"fff7c70e.630178","type":"proximiio-event-receiver","z":"b56d02c7.907db","delete_event":true,"x":413,"y":261,"wires":[["2ccf8998.05d366"],[]]},{"id":"95ae085.e81a3f8","type":"http request","z":"b56d02c7.907db","name":"Post","method":"POST","ret":"txt","url":"PASTE YOUR URL HERE ","x":663,"y":544,"wires":[[]]},{"id":"2ccf8998.05d366","type":"switch","z":"b56d02c7.907db","name":"Enter type filter","property":"event","propertyType":"msg","rules":[{"t":"eq","v":"enter","vt":"str"}],"checkall":"true","outputs":1,"x":519,"y":348,"wires":[["5a7764d4.1c3cec"]]},{"id":"5a7764d4.1c3cec","type":"function","z":"b56d02c7.907db","name":"Prepare POST","func":"msg.headers = {\n    \"Content-Type\" : \"application/x-www-form-urlencoded\",\n};\n\nmsg.payload = \"text=\" + msg.data.geofence;\n\nreturn msg;","outputs":1,"noerr":0,"x":602,"y":444,"wires":[["95ae085.e81a3f8"]]}]

actions_5

Step 2 : Once the above code is imported the action flow would look like below .

action flows 1

Here’s the full walk-through of each of the steps and what’s happening in the action flows:

Proximi.io Event Receiver
This node listens for visitors entering or exiting any of the defined geofences. When a proximity event occurs, the node get’s triggered and it will pass all the event data as an output payload.

Switch node
A Switch node can be used to segment the action flow based on the event type, department and a lot of other properties as well. You can check out all the properties from our REST API documentation. In this case we’re reacting only to “enter” events.

event_type_enter

Function node
A Function node allows you to use JavaScript to add custom logic which might not be possible with other nodes. The Function block modifies the Msg object. Msg is an object that travels through the flow. In this example we are setting the msg.headers and msg.payload ready for the next block. This is standard format for the HTTP Request. In header, the content type is specified, and then in the payload, which is the body of the request, we set the data that we want to send.

When you double click on the Prepare Post Function node you can see as below. In msg.payload, you can define any message that you would like to send to the URL. msg.data.geofence will return the name of the geofence on every event that happens on a particular geofence created.

function_prepare_post

HTTP Request
This sends the HTTP Post request as specified. it uses the msg.headers property as headers, and msg.payload as the body of the request  to the specified URL. Copy the URL from Webhook Tester site.

url_paste_send

Step 3: Deploying the action flow : You can deploy the action flow from the top right corner of the editor. Usually it’s good idea to select the first option “Full”.

Deploying the action flow

You’re all set! The result should look something like this:

About Annina Koskiola

CEO and Co-founder of Proximi.io. Loves exploring new ways for technology to intertwine with our everyday lives. Passion for history, traveling, eating and the Valais Blacknose sheep.