Interact with Tableau Server with tabcmd - export workbooks/views

by Gaia Fantini

Yesterday, as part of the training at the Data School, I have been introduced to the Tableau Server command line utility, tabcmd. It allows to interact with the server from your local machine from the Command Prompt. Why am I showing you this? Well, the tabcmd allows to the user to interact without going and clicking directly into the browser window, which means it is very useful in case the user wants to run automated process. It is possible for instance to schedule a script to run at a certain time or with a certain frequency, and download data every day at the same time, or uploading a workbook at a specific moment...

Let me show you a couple of things you can do with this.

First, you will need to open the Command Prompt app on your machine: you can do this by typing cmd in the windows search bar. Starting it, will bring up a black window when you can type in line commands. To use the tabcmd commands you first need to point to the directory where the Command Line Utility lies. You can use the change directory instruction to do so (cd), followed by the path for that folder:

By changing the current directory to the specified one, you can run all the tabcmd instructions, but to send commands to the Tableau Server you need to login first.
The function is tabcmd login followed by few extra parameters specifying the server in which you want to login, the site to access, and the user name. It will then ask for a password (be aware: the password will be hidden, so the cursor will not move nor the word will be shown while typing in). These must be the credentials that you normally use to access the server.

If your credentials are correct, you will get a "Succeded" message. Congratulations! You are now logged in and can ask a lot bunch of stuff to the server!
To see a list of everything that can be done, follow this link for the list of all tabcmd Commands

Today I will show you how to export workbooks and views from the server and save them on your local machine.

Export a workbook in pdf

To export from the server you will need to follow few steps: first, you need to specify the view, workbook or data you wish to export. Look for the URL that identify what to export and copy the strings in this format "workbook/view". You don't need anything from the URL before this string nor the iid= session ID at the end of the URL. Then you need to make sure you are on the right site. I am logged in to the Data School site, and I will export a workbook from there, if this is not the case you can use the command -t <sitename> to go to the right site.
You then need to specify the format in which you want to save your workbook and the location: since I want to export the whole workbook I chose --fullpdf and the location is specified by the command -f.
Note: the file extension must be included in the name of the file you provide when specifying the location. Remember: if the path includes spaces, it need to be enclosed within quotation marks.

Once you run the commands, you can see the outcome of it: in the last two lines of this script you can read that the workbook has been saved and the location where it is stored.
Here it is the downloaded workbook in pdf:

Export a view as excel

Now I want to show you how to export a view as a .csv file. The process is similar: I chose another work this time as I wanted something that would looked good in a table format: I went for this project

and the resulting table will include the data used for the view

Similarly to before you will use the export command and you will have to specify the file type, file name and the location where you want to export it. The complete command line in my case is this:

tabcmd export Regional/Health --csv -f "C:\Users\Gaia Fantini\Desktop\Tabcmd Practice\exportview.csv"

again, since there are spaces in the name of the folder where I am saving the file, I am putting quotation marks around it. Let's run it and see the outcome:

NB I was getting some error initially and I had to change the \ to a / in the URL. Now the file can be opened with Excel:

Here is the outcome of the export: a table, including the data used to build the charts in the view, which I saved in the same folder as the previous export.

Done! It can look scary at first if you never used the command prompt before, but after you get the grip of it, it comes pretty straight forward. Just have at end the list of commands and read carefully any outcome of the script: if you have any error, you will find there important details about the error and in most case, the solution to the problem. Most of the time is about how the commands are written, but this just takes practice.