3/10/2019
Using the Tableau Public API in 3 Easy Steps


In this blog post I will outline how you can get quick and easy statistics on any Tableau Public Profile using the Tableau Public API, and how to batch download Tableau workbooks from a Tableau Public Profile page. There are already some good blog posts on this topic and a terrific community resource called The Cerebro Project that was built and is maintained by Josh Tapley. However, it's pretty easy to pull your data, or anyone's data, using the Tableau Public API in just a few steps.


Step 1: Build a URL using the Tableau Public Profile Name


The URL is pretty straight forward:
https://public.tableau.com/profile/api/[Profile Name]/workbooks?count=300&index=0

For example, to pull the data for my Tableau Public Profile I would use this URL:
https://public.tableau.com/profile/api/jeffrey.shaffer/workbooks?count=300&index=0

The data will return in JSON format. Right-click and save the file.

Step 2: Load into Tableau (or parse the JSON if you like)


You could parse the JSON with any number of tools, for example using Alteryx, but there really is no need to do this since Tableau can import JSON directly.

Select Data in the menu and select "New Data Source".
Choose JSON and select the file.
The default schema selection should work without any configuration, so click OK.

You now have the data in Tableau.

Step 3: Build a Viz


Below is a sample viz that shows the information from my Tableau Public Profile page. The fields are pretty self-explanatory. I created two calculated fields that are built by combining a few fields into a URL, one for the Thumbnail view and the other to download the Tableau workbook.

Calculated Field: Thumbnail
Formula:
// https://public.tableau.com/thumb/views/BarHoppingThemeandVariationsonaBarChart/BarHopping
'https://public.tableau.com/thumb/views/' + [Workbook Repo Url] + '/' + replace(replace([Default View Name]," ",""),".","")

Calculated Field: Full URL
Formula:
// https://public.tableau.com/workbooks/BarHoppingThemeandVariationsonaBarChart.twb
'https://public.tableau.com/workbooks/' + [Workbook Repo Url] + '.twb'

Using a dashboard action we can view a thumbnail of a viz or download the viz. There are also fields that you might useful, for example; View Count, Number of Favorites, Allow Data Access, Show in Profile, and Revision.


Update: Thank you Annabelle Ricon for catching the bad date format and providing a formula to convert to a proper date.
Calculated Field: Date
Formula:
// Date First Publish converted to a date format
// Thank you Annabelle Ricon for catching this and providing a formula to resolve the date
date(dateadd('second', int(int([First Publish Date per Document])/1000), #1970-01-01#))

Using a dashboard action we can view a thumbnail of a viz or download the viz. There are also fields that you might useful, for example; View Count, Number of Favorites, Allow Data Access, Show in Profile, and Revision.



Batch Download Visualizations or Images


Back in December 2017, I wrote a blog post on how to batch print PDF for Tableau Public or Tableau Server. One of the additional features I outlined in this post is that you can batch download PNG, CSV or TWBX files. We can use the list of Full URLs that we created from the JSON output above to create a list of visualizations. Once we have the list, we can leverage the steps from my batch PDF blog post to batch download all of the visualizations from a Tableau Public account.

Follow the steps above to get the JSON, import into Tableau, create the FULL URL field (or use Thumbnail to download all of the images). Then copy the contents of that field to get a list of links. Simply drop the list of links in place of the list of PDF links in that blog post.


Below is the sample HTML code used to create a download button to download 10 visualizations from my Tableau Public Profile page:
Note: see the browser restrictions outlined in the December 2017 blog post.



I hope you find this information useful. If you have any questions feel free to email me at Jeff@DataPlusScience.com

Jeffrey A. Shaffer

Follow on Twitter @HighVizAbility