Tableau Server subscriptions for admins in a hurry

How to create subscriptions using Python and Tableau’s REST API

Elliott Stam
Mar 11, 2020 · 6 min read
Photo by jesse ramirez on Unsplash

Setting up Tableau Server subscriptions can really bum you out. It makes me think of something I heard someone say in a bar, obviously talking about something he wanted nothing to do with: “I’d rather cut my toenails with a lawnmower.” What a legend.

In this article, we are going to explore how you can put that lawnmower away, which will make for way better-looking toe nails, and will put you in a position to sip margaritas while automating the process of subscribing users.

This tutorial walks through using the Python tableau-api-lib package and is part of a series on how to tap Tableau Server like a keg, giving you control over Tableau Server’s REST API.

These tutorials assume you have Python 3 installed already. If you do not have Python 3 yet, this will get you started: guide to install Python.

Here’s a hypothetical situation: one day, your team lands a new hire. They’re super great — and they need access to Tableau Server. Last month, you set up subscriptions for everyone in the ‘Super Dope Employees’ group on Tableau Server. It was easy! You just subscribed the entire group. However, simply adding this user to that group is not going to subscribe them to the same content your existing users are subscribed to. Nope, you’re going to need to manually subscribe Timmy or Janet to get the job done.

Now, we have users and groups. We also have schedules. In the steps that follow, we are going to write code that allows our users to receive visuals via email at specific time intervals defined by one or more of our schedules.

That’s where the REST API comes in. Equipped with a library like tableau-api-lib, you’re on your way to automating your Tableau Server environment.

This library gets updated on a very regular schedule. It can’t hurt to run this command even if you already have the library installed.

pip install --upgrade tableau-api-lib

If you’re new to Python or want more information on the basics of getting set up, follow this getting started tutorial. That tutorial walks you through getting connected to Tableau Server using tableau-api-lib.

Use the code below as a template for getting connected to your server. In future steps, we will build upon this boiler plate with one-off lines of code. At the end of the article, you’ll find a consolidated block of code you can copy / paste for your convenience. I gotchu.

from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_schedules_dataframe, get_users_dataframe, get_views_dataframe
tableau_server_config = {
'tableau_prod': {
'server': '',
'api_version': '<YOUR_API_VERSION>',
'username': '<YOUR_USERNAME>',
'password': '<YOUR_PASSWORD>',
'site_name': '<YOUR_SITE_NAME>',
'site_url': '<YOUR_SITE_CONTENT_URL>'
conn = TableauServerConnection(tableau_server_config)

Fun fact: you can also use personal access tokens, assuming you are on Tableau Server 2019.4 or newer. If you’re all about the access tokens, check out my article for details on how to use them.

Let’s take a look at our available subscriptions.

schedules_df = get_schedules_dataframe(conn)

Running the get_schedules_dataframe() function fetches us a Pandas DataFrame packed with all of the schedules available to us.

Here’s a glimpse of what you can expect your schedules_df to look like:

A subset of schedules on my test server.

Let’s zoom in on the schedules which are eligible for our subscriptions.

schedules_df[schedules_df.type == 'Subscription']

Here’s what my output looks like:

Here are my subscription-specific schedules

Great — now I can see that most of my schedules are suspended, which means I probably want to be careful about which ones I choose to use. I can also see that this DataFrame gives me easy access to the schedule IDs, which we’ll need in the next steps.

If you are subscribing a user you just created, you can automate the whole process: create the user, pass the new user’s ID to the command to create subscriptions, add the same user to groups, etc.

However, that’s all open-ended. In this tutorial, let’s maintain focus on the actual subscription component. To demo the functionality, I’m going to conjure up a DataFrame of my views and my users so I can subscribe a random piece of content to one of my random users.

users_df = get_users_dataframe(conn)

With that, I’ll cherry pick a user ID from my user DataFrame (users_df).

The chosen one is ‘elliott be teaching’, because I like the email address.

Now I just need a piece of content to subscribe my user to.

views_df = get_views_dataframe(conn)

I’ll use the first view ID from my views DataFrame(views_df).

The finale! All the work has already been done, so… let’s wrap this thing up. First, we need to know a little about the create_subscription() method.

The help() function will display internal documentation for any tableau-api-lib method.

Now let’s hit the big button and do what we came here to do.

response = conn.create_subscription(schedule_id=sample_schedule_id, user_id=sample_user_id, content_type='view', content_id=sample_view_id, subscription_subject='Sample subscription subject', attach_pdf_flag=True, attach_image_flag=True)

If your subscription is successfully set up, the response will look like this:

I lied earlier — I ended up using a real user so I could get my subscription!

Just to double check it’s all working properly, I’ll go ahead and trigger that schedule to run so I get my subscription.

It works!

If you’re at work, maybe just get an iced tea instead. Unless you have beer at work — in that case, get that tea out of my face!

Now that you have your subscription working, it’s time to think big-picture. In future posts, I’m going to be taking a closer look at how we can combine what we’ve learned here with some other REST API functionality, which will lead to some powerful results. One of those articles will cover how we can loop through all users in a group and subscribe them to content. In an ideal world, you will have processes completely automated.

Imagine if when you onboarded a new team member, you could click ‘run’ and they would be automatically added to your Tableau site, added to the appropriate groups, and subscribed to relevant content the rest of the team has subscriptions to. Man, what a time to be alive.

That’s it for this tutorial! As always, reach out if you need any pointers or help.

Click this link to navigate to the GitHub Gist posted above.


Delivering insights into Tableau Server automation and data…

Elliott Stam

Written by

Data scientist and author. Sometimes seen falling down mountains with a snowboard strapped to my feet.



Delivering insights into Tableau Server automation and data visualization.

Elliott Stam

Written by

Data scientist and author. Sometimes seen falling down mountains with a snowboard strapped to my feet.



Delivering insights into Tableau Server automation and data visualization.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store