Publishing workbooks to Tableau Server through Alteryx

Alteryx and Tableau have a fantastic working relationship, with easy integration in a lot of cases. Alteryx can also work well with Tableau server, where through the Tableau Server API users can perform many tasks. One task that is not so simple, however, is publishing to Tableau Server through Alteryx. A tool exists for publishing datasources, but it isn't as easy to publish workbooks. In my experience this is because of a limitation with the Alteryx download tool, but more on that later. I recently completed a project involving publishing workbooks with Alteryx - this is the method I used.

To accomplish this I used the cURL function through command line to access the API. In Alteryx you can create "batch" files that will run multiple requests on command line automatically. Running the correct cURL commands with the correct contents and file links will let you publish workbooks in bulk to Tableau Server.

The Tableau Server API documentation tells us exactly what we need to send in the 'request body' in order to publish a workbook:

This is where we find the limitation of the download tool in Alteryx - it struggles with 'mixed content bodies'. Here for example, one part of the request body is text and one is a file.

The Workflow

My method has three steps. First the top (text) part of the request body is generated and saved to your local machine as a .xml. Then we need to build the rest of the request, including the URL and content headers. Finally we use the "Run Command" tool to send the request, including the URL, content headers, .xml file and  the tableau workbook file. Let's see how we build all of these parts.

First we'll build and save the .xml file. Note that you can include any argument listed in the documentation here - I've just kept it simple.

I also create a filepath in this step - and after creating this I output it to the created filepath. Note - you may need to use the "Block Until Done" tool to ensure these files are written before the rest of your workflow continues.

Now let's build the full request:

'curl "'+ [Base URL] + 'sites/' + [site_id] +'/workbooks?overwrite=true" '+ '-X POST -H "X-Tableau-Auth:' +[X-Tableau-Auth]+'" -H "Content-Type: multipart/mixed;" -F "request_payload=@publish-' +[workbook_id]+'.xml" -F "tableau_workbook=@' +[workbook_id]+ [Type] + '"'

Note that you will need to have authenticated with Tableau Server to get the X-Tableau-Auth token - there are plenty of tutorials for this online. This will also only work if you have chosen the same filename formats as me:

Workbook Filename : FilePath\[workbook-id].twb(x)

XML FileName: FilePath\publish-[workbook-id].xml

If you haven't you will have to change the URL request.

We can now publish our workbooks. If we are batch uploading, we will have to concatenate all of our requests with a newline separator. Now, let's have a look at the setup for the "Run Command" tool.

In this configuration - the incoming data is saved as a .bat file to a temporary folder. Command line then runs from the same temporary directory.

With a bit of luck, this should let you batch-publish workbooks to Tableau Server.

Troubleshooting Tips:

Double / Triple check all spelling and syntax, this is very sensitive to anything it doesn't expect and it won't always tell you why.

Check all filepath are correct. The command may not be looking where it is supposed to be looking.

I found that the "code page" used for writing the .bat file can cause some errors. ANSI gave me the best results.

Author:
Finn Charlton
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab