Send a Slack notification when a workbook is updated - tableau/datadev-hackathon GitHub Wiki
API: Webhooks | REST API
Difficulty: ⚫⚫⚪⚪
Requirements: Postman (Free), Free Developer Site, Glitch Account (free)
This mini-project will show you how to set up a webhook that sends a notification to your Slack whenever a workbook is updated. Webhooks let you build custom applications or workflows that react to events that happen in Tableau. They have a payload of information and are sent to a specific URL for a receiving web service. For this tutorial, you are going to send to a Glitch application, and not to Slack directly. Tableau is sending a specific paylod when the event is fired, the payload varies based on the type of event, but it is fixed. But if you want to send a message using Incoming Webhooks in Slack, the HTTP POST request is different from the payload that Tableau is sending. You need a middlemen to translate the Tableau payload to the payload that Slack is expecting. This middlemen is going to be our Glitch application.
Set up Slack to send messages using Incoming Webhooks
All the instructions can be found on the Slack website.
Once you have created a Slack app, copy and paste your webhook URL in a safe space. It should look like this:
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
You will need it later.
Remix the Glitch project to create your own
- Remix the Glitch project by clicking here
- Optional - Sign in to Glitch to save your work for later
- Modify the constant: SLACK_URL with your unique Slack webhook URL that you got in the previous step. The URL should look like:
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
- Copy and Paste the URL of your Glitch project in a safe place. You can find your Glitch project by clicking on the top left icon: "Show" > "In a New Window". Your Glitch's URL should look like:
https://[project-name].glitch.me/
Optional: If you want to edit the message sent to Slack, you need to edit: slackBody.text field
Set up the Postman collection
You created a Glitch project that is going to receive a webhook from Tableau Server/Online, transform the webhook payload to fit Slack's requirements, and send the transformed payload to Slack. You now need to set up Tableau Online to send the webhook to the Glitch project. First, let's get the environment set up.
- Download and open Postman.
- Download the Postman collection for Webhooks (Right-click and Save As).
- Click File > Import > Choose Files and choose the Postman collection you downloaded. The collection will then appear on the left.
- To configure the variables in the collection, click the cog in the top right corner of the window. This will open the Manage Environments window.
- Click Add at the bottom.
- Give your environment a name based on the Tableau Online site you plan to use for this mini-project. If you do not have access to a server you can sign up for a free development sandbox site through our Developer Program!
- Next, add the following variables that are specific to your Tableau Server instance. If you are using a server versioned 2019.4 or higher you can use the more secure Personal Access Token (pat-name & pat-secret), otherwise, add username & password.
Variable | Current Value |
---|---|
server | https://10ax.online.tableau.com/ |
username | jamiedata |
password | SecureP@$$word |
pat-name | demo |
pat-secret | 1qKESh1AtahNA1bn68+Gg==:fHmahHT2sK2j6eHE3CSHrFakemPpkey3ku |
Note: To create a Personal Access Token go to your Tableau Server and click your profile icon in top right. Select My Account Settings, on that page find Personal Access Tokens and type in a name for your token and click Create new token. Copy and take note of the token somewhere as you will not be able to see the token again.
- Click Add
- Close the Manage Environments window.
- Make sure that the dropdown box to the left of the cog you used to open the Manage Environments window is set to the environment you just created. This will populate the variables in the collection with your actual Server values.
Sign in to your server
Authenticate into the Tableau Server.
- Drill down on the webhooks collection on the left (this tutorial will be using JSON) and click on the Sign-in item (depending on what variables you set earlier choose the username & password option or the personal access token option), this will create a new tab for your request.
- Click on Body and you should see the following (or similar with user/pass):
{
"credentials": {
"site": {
"contentUrl": ""
},
"personalAccessTokenName": "{{pat-name}}",
"personalAccessTokenSecret": "{{pat-secret}}"
}
}
- Add your Tableau Server site content URL to the body.
Note: the contentUrl is what you see in the address bar when you go to that site on Server. For example: "My Awesome Site" might be "myawesomesite".
{
"credentials": {
"site": {
"contentUrl": "myawesomesite"
},
"personalAccessTokenName": "{{pat-name}}",
"personalAccessTokenSecret": "{{pat-secret}}"
}
}
- Click Send
- If everything was successful, below the body you should see a response similar to this:
{
"credentials": {
"site": {
"id": "7ah7244b-g106-f4k3-b5cb-960053c9982qu",
"contentUrl": "myawesomesite"
},
"user": {
"id": "db9lo9b2-1hg3-46h4-824f-6a09abid109cx"
},
"token": "QHUpb3fsRH6AQuQhfharpRQ|UZgGf4k3aAOokMtFaNOfHKd7CcbB0My8QWLf"
}
}
- Take note of the response text somewhere as you will need it for subsequent requests.
- Open the Manage Environments window again and select your environment to update it. Add the following new variables based on the response text:
Variable | Current Value |
---|---|
site-id | 7ah7244b-g106-f4k3-b5cb-960053c9982qu |
tableau-auth-token | QHUpb3fsRH6AQuQhfharpRQ|UZgGf4k3aAOokMtFaNOfHKd7CcbB0My8QWLf |
- Click Update and close the window.
Create the webhook
- Next, let's add variables to our environment for the webhook itself. Open the Manage Environments window again, click on your environment and add the following variables:
Variable | Current Value |
---|---|
webhook-source-api-event-name | webhook-source-event-workbook-updated |
webhook-url | https://[project-name].glitch.me/incoming |
webhook-name | my_first_webhook |
Note: you can see a list of the available webhook events in the documentation. The URL is the one that you noted from IFTTT earlier and you can choose any name you like.
-
Click Update and close the window.
-
In the side panel click on the Create a webhook item then click on Body and you should see the following:
{
"webhook": {
"webhook-source": {
"{{webhook-source-api-event-name}}": {}
},
"webhook-destination": {
"webhook-destination-http": {
"method": "POST",
"url": "{{webhook-url}}"
}
},
"name": "{{webhook-name}}"
}
}
- The variables will be populated automatically from the variables you just set. You may also notice your tableau-auth-token is being used in the headers.
- Click Send. If it was successful you should receive a response like this:
{
"webhook": {
"webhook-source": {
"webhook-source-event-workbook-updated": {}
},
"webhook-destination": {
"webhook-destination-http": {
"method": "POST",
"url": "https://[project-name].glitch.me/incoming"
}
},
"owner": {
"id": "b9c3217d-t38t-4248-f4k3-97736a2ee9d8",
"name": "jamiedata"
},
"id": "58a6c974-4f5c-f4k3-b766-8c5d877a6d6f",
"name": "mini_project_1"
}
}
- You want to take note of the id of the webhook and add it to our environment variables. Again, open the Manage Environments window and add a variable called
webhook-id
with the id you see in the response (ie:58a6c974-4f5c-f4k3-b766-8c5d877a6d6f
). Note: make sure you grab the webhook id and not the owner id!
Test your webhook
Let's make sure it works.
- In the side panel, click on the Test webhook item and click Send.
- If it is successful you will receive the following response
{
"webhookTestResult": {
"body": "{\"result\": \"success\"}",
"id": "58a6c974-4f5c-f4k3-b766-8c5d877a6d6f",
"status": 200
}
}
Even if the test is successful, you will not receive a Slack message as the payload is empty.
Try it out for real
Now let's see it from actual workbook update.
- Using the Web Edit on Tableau Online, edit an existing work and save it. Note: No need to change anything on the workbook, save is going to trigger the Webhooks
- If you did everything correctly you should receive a Slack message! Congratulations!