Tutorial
Send a notification when a workbook is created
This tutorial will show you how to set up a webhook that sends a notification to your phone whenever a workbook is created. Webhooks are automated messages sent from Tableau Server/Online when something happens. They have a payload of information and are sent to a specific URL for a receiving web service. Today's web service will be IFTTT's notification service.
Set up the receiving service
First, we need to set up the notification service to be activated based on receiving a webhook message. IFTTT stands for "If This Then That", in our case if a webhook is triggered then send a notification.
- If you do not already have an IFTTT account you can sign up for one here.
- Once logged in, click on your profile in the top right corner and select Create to create a new applet.
- Select this, then search for and select Webhooks.
- Choose the trigger of Receive a web request.
- Give your event a name, like WorkbookCreated (remember this for later) and click Create trigger.
- Select that, then search and select Notifications.
- Choose the action Send a rich notification from the IFTTT app.
- Edit the title and message that is being sent, they will be generic for now and click Create action. You can add links and images later.
- Click Finish.
- Download the IFTTT app on your phone and log into your account.
Test the IFTTT setup
Let's make sure that we did it right.
- Click on your profile and go to My Services.
- Click on Webhooks.
- Click on Documentation.
- Under "Make a POST or GET web request to:" edit the {event} to what you named your event above. (ex: WorkbookCreated)
- Click Test It and you should get a notification!
- Copy down the full URL you see under "Make a POST or GET web request to:" as we will need this to set up our webhook in Tableau Server. It should look something like this: https://maker.ifttt.com/trigger/WorkbookCreated/with/key/makF46ZIbtPbEv3CJTal_t
Note: make sure the event name is in there, it may not copy directly.
Set up the Postman collection
We've set up IFTTT to receive a webhook, we now need to set up Tableau Server to send the webhook to IFTTT. 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 Server instance 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 | |
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. 8. Click Add 9. Close the Manage Environments window. 10. 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 respnse text somewhere as we 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
Link to the IFTTT applet from Tableau Server.
- 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-created |
webhook-url |
https://maker.ifttt.com/trigger/WorkbookCreated/with/key/makF46ZIbtPbEv… |
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. 2. Click Update and close the window. 3. 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 but 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-created": {} }, "webhook-destination": { "webhook-destination-http": { "method": "POST", "url": "https://maker.ifttt.com/trigger/WorkbookCreated/with/key/makF46ZIbtPbEv3CJTal_t" } }, "owner": { "id": "b9c3217d-t38t-4248-f4k3-97736a2ee9d8", "name": "jamiedata" }, "id": "58a6c974-4f5c-f4k3-b766-8c5d877a6d6f", "name": "mini_project_1" } }
- We 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 and should receive a notification on your phone!
{ "webhookTestResult": { "body": "{\"result\": \"success\"}", "id": "58a6c974-4f5c-f4k3-b766-8c5d877a6d6f", "status": 200 } }
Try it out for real
Now let's see it from actual workbook creation.
- Either create a workbook in Desktop and publish it to your Server or create a new workbook directly within Server with Web Edit.
- If you did everything correctly you should receive a notification! Congratulations!
Challenge exercises
Now that you know the basics of webhooks, try implementing the following bonus challenges.
- Change the output method to send an email.
- Create a different webhook for data sources being refreshed successfully.
If you would like to check out how to customize the message being sent, check out this sample!
Dernière mise à jour : septembre 10, 2021