FME Version
Files
-
- 9 KB
- Download
Introduction
There is a huge benefit to using webhooks as a means of instant notification - if your client needs updates for specific events, creating a webhook for those events will enable them to receive and disseminate information about that event into their automated workflows. A webhook allows one system to receive data from another system in real-time. Instead of polling a source system for new data, events in the source system automatically send data to the target system.
Webhooks are HTTP (POST, GET) callbacks that are sent to user-defined URLs in response to triggers or events. The use of webhooks allow for third party data integration with existing services, such as FME Flow (formerly FME Server).
Using webhooks is nearly as simple as entering a URL into the address bar of any web browser. The URLs are almost always contained on one line, and there is no requirement to write code!
As an example, imagine that you have a webpage where users can post data. You could setup a webhook to track new postings. When new data is posted, the HTTP POST method is used to send the data to your webhook URL, typically as a JSON payload. The data can then be digested as part of workflows or propagated to other systems using subsequent webhooks.
Receiving Data Using the Webhook Trigger
A Webhook trigger in an FME Flow automation can be used to receive information from third-party applications and start the automation. When a third-party event configured to the direct URL occurs, it will trigger the FME Flow automation. The automation can then use JSON data received through that webhook to perform additional tasks such as delivering data via email or updating a database, based on the protocols you have set up.
There are three main steps to setting up a Webhook trigger for an FME Flow automation:
- Create a new Automation with a Webhook trigger
- Configure the Output Attributes to accept JSON sent from a third-party application
- Save the Automation to get the Webhook URL
Sending Job Information to a Webhook
The power of FME Flow doesn’t stop with enabling third-party apps to send messages to FME Flow via webhooks. In fact, FME Flow has the ability to submit data to URLs, which includes webhooks – this means that FME Flow can be used with any third-party services that utilize webhooks!
Through some simple configurations, and without writing any code, an FME Flow automation can send information about successful (or failed) jobs to Slack via the HTTP Request action. This provides an easy and effective way to monitor transformations or other actions with FME Flow.
The example automation pictured below is driven by a Resource or Network Directory trigger, which monitors a Resources folder for new files. When a file is created in the folder, it gets sent to a sample translator workspace which is set to convert it to a different file format. Lastly, details about the job are sent to Slack using the HTTP Request action so that a user receives an update when the file conversion job is complete.
To recreate this example, you will:
- Configure a Slack Workflow with a Webhook URL as the endpoint for delivering a message
- Set up a simple FME Flow automation to send data through the webhook
- Test the automation to trigger the Slack Workflow and deliver a message to a channel or user
Step-by-step Instructions
1. Configure the Third-Party Service | Slack
To get started, we need to set up a Slack Workflow with a webhook trigger that will send a message to our desired user or channel. In Slack, click More under the Activity tab, then select Automations. Select "New Workflow," then "Build Workflow" to open the Workflow Builder. For more information on Slack Workflows, see their documentation.
Name your new workflow, then choose to start the workflow "From a webhook."
Set up the variables expected in the webhook body by inserting their keys and types. For this example, we will be using the keys "jobID" and "jobResult." Each variable will be Text. Next, click continue to generate the Webhook URL.
Add the next step in the workflow. Select Messages, then "Send a message to a person." You can also send a message to a channel if you would prefer. Choose the user or channel you will be sending the message to, then draft the body of the message using the variables defined in the prior step.
Finally, save and publish the workflow. The URL will look similar to https://hooks.slack.com/triggers/X04XXXXXX/XXXX868247073/XXXc910791184xxx880xxxbd63x19xx3 and will be used as the Target URL parameter in the HTTP Request Details.
2. Configure the Automation | FME Flow
Create a new Automation in FME Flow and add a Resource or Network Directory trigger. Change the following information:
- Directory to Watch: Add the directory you would like to upload sample data to. I have created a new Resources folder for this example.
- Watch Subdirectories: No
- Watch Folders: No
- Events to Watch for: CREATE
- Poll Interval: 5 Seconds
Next, add a Run a Workspace action and connect it to the Success output port on the Directory Watch trigger. Change the following information:
- Repository: Samples
- Workspace: easyTranslator.fmw
- Source File: Select the dropdown next to the field, then open the Directory parameters to find File Path
- Destination Format: GeoJSON (Geographic JavaScript Object Notation)
Lastly, add an HTTP Request action and connect it to the Success output port on the Run Workspace action. Change the following information:
- Request Type: POST
- Target URL: Insert the Slack Webhook link from step one
- HTTP Body (optional): { "jobResult": "{job.status}", "jobID": "{job.id}" }
3. Verify the Slack Webhook Integration | FME Flow
Start the Automation to begin watching your directory for new files. Upload sampleSuccess.kml and sampleFailure.kml to the watched directory. Observe the results in Slack after the job completes.
Testing and Debugging Webhooks
Verifying the Webhook Payload
RequestBin provides a URL that can used in place of the Slack Webhook URL. This service can be used to inspect exactly what FME Flow is sending. RequestBin can also be used to see what other third-party services are providing. It's a useful tool for debugging each request.
Providing Sample Webhook Input
Hurl generates HTTP requests that can be directed towards Webhook URLs. Instead of using FME to create and send the JSON message, this tool can be used to send your own message to any third-party service. This is particularly useful for testing scenarios where FME Flow is providing the webhook.
Data Attribution
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.
Comments
0 comments
Please sign in to leave a comment.