Building Vessels to Reference Fleet Webhook Parameters
Overviewβ
In this tutorial, you'll learn to build a Fleet that contains a Vessel that can parse the received webhook parameters. This tutorial is only in Python (for now).
By the end of the tutorial, you'll be able to:
- Set up a Vessel with Code
- Upload a script to Platform.
- Reference platform environment variables
- Check Logs to verify that a Vessel correctly referenced the webhook parameters.
Setupβ
First, download this code, named webhook_parameters_reference.zip
to your computer without making any changes.
Feel free to peruse this script beforehand so you understand everything that it's doing. The script is accomplishing four main things:
- Reads in the Platform environment variables for the paths to the conditional headers and body files.
- Conditionally reads in the headers and body files (the body is assumed to be a JSON file in this example).
- Loops over the key-value pairs for both files and prints each one out
In the event that either headers or body are not provided in the webhook invocation, those loops are skipped.
Stepsβ
Using the sidebar, click + New Fleet. You'll now be on the Fleet builder canvas. Next we'll walk through the process of building the required Vessel and invoking the Fleet with a webhook.
Step 1 - Create a Code Vesselβ
- Click Python under the Code Vessels dropdown.
- Under the Code dropdown in the File to Run input, type
webhook_parameters_reference.py
. - Click the Upload toggle option.
- Click the Upload File button and select the
webhook_parameters_reference.zip
downloaded in the Setup section above. - Click Save & Finish in the bottom right corner of the canvas.
Step 2 - Add a Fleet Webhookβ
- On the success page, click the Add Triggers button.
- Under the Triggers tab, click the Add Webhook button on the right side of the screen.
- Copy and paste the generated URL for Step 3 below.
Your generated URL will be different than the one pictured above.
Step 3 - Invoke the Fleet Webhookβ
- Open up a browser and navigate to this URL.
- Copy and paste the code below into the text box while replacing the
<webhook_url>
value with the one generated in Step 2.
curl -X POST <webhook_url> -H "Content-Type: application/json" -d '{"action_id": 123456, "action_name": "new action"}'
- Click the Send button.
Step 4 - Examing the Webhook Parametersβ
- Click on the Logs tab on the Platform browser tab.
- Click on the Fleet in the Runtime History histogram (it may be yellow if running or green if complete).
- Click on the Vessel in the Overview tab (it may be yellow if running or green if complete).
- You'll see the output in the logs showing the headers and body values.
- Click the back arrow to the left of the Vessel Log ID.
- Click on the Webhook Parameters tab to see the values received from the webhook in JSON format.
You have successfully created a Fleet with a Vessel that can parse the received webhook parameters.