This member-only story is on us. Upgrade to access all of Medium.
Member-only story
TABLEAU REST API: TABLEAU-API-LIB TUTORIALS
Tableau Server impact analysis
reports: accessing metadata
A series focused on improving your team’s productivity using
interactive visuals to track data lineage
Elliott Stam · Following
Published in Towards Data Science · 8 min read · Apr 26, 2020
107
3
Metadata helps you keep track of your Tableau environment (Photo by Aron Visuals on Unsplash)
All good adventures begin with a first step. In this tutorial, the first step we
take to build an impact analysis report for Tableau Server is collecting
information about the relationships between our workbooks, visuals, and
underlying database assets.
If you have no idea what I’m talking about, take a few minutes to check out
the intro post, which kicks off this series of tutorials demonstrating how we
can build impact analysis reporting for Tableau.
To summarize, our goal is to pull valuable metadata that exists in every
Tableau ecosystem and provide an outline for how you can spin that data
into insights. This is all about improving the productivity of our data teams
and providing tailored visual information about our data lineage that anyone
capable of clicking a mouse can easily interact with.
So let’s get started!
What we accomplish in this tutorial
I want to get into the how as quickly as possible, but explaining the what is
important. Our first step requires us to get our hands on some crucial
information that will allow us to answer these types of questions:
1. How many of our visuals will be impacted if a specific database asset
goes down? How can we know exactly what data feeds into our Tableau
Server environment?
2. Are the impacted visuals dashboards or just worksheets? What types of
connections do they have, and are these connections embedded in
individual workbooks or are they published?
3. Do we have a lot of duplicated connections that could be consolidated
into published datasources for better scalability and governance?
4. Considering all the database connections we use, which specific tables
are the most critical? How many Tableau workbooks reference those
tables?
We could go on, but I think you get the point. The repeating themes of these
questions are: workbooks, datasources, and database tables.
Let’s dive into this tutorial’s mission: pulling data from the Metadata API and
shaping it into something that gets us closer to answering the questions
above.
There’s more than one way to skin a … metadata
The saying goes, “there’s more than one way to skin a cat.” I’ve always liked
cats, so I never loved this phrase. The reason I bring it up is that it’s wildly
appropriate for the situation we find ourselves in with Tableau’s Metadata
API.
For starters, you can take the no-code approach, or you can flip that on its
head and do everything with code. Yep, there’s something for everyone.
We’ll begin with the no-code approach. You can use this to throw together a
quick proof of concept or rely on it as your go-to data collection method if it
provides exactly what you need and you don’t mind a bit of manual labor.
After covering the no-code approach, we’ll stretch our Python muscles and
pave the way for you to integrate the Metadata API into automated
workflows. Going the Python route will also allow us to do some nifty things
such as enriching our metadata with contextual information available
through other sources.
Regardless of your chosen method, you’re going to need to be on Tableau
Server 2019.3 or later in order to use the Metadata API. If you use Tableau
Online, you’re good to go. Did you know you can request a free Tableau
Online sandbox site by joining their developer community? Now you know.
That covers the scope of this tutorial, though I think I’ll toss in one or two
basic Tableau visuals at the end to prove that the data we pull is real and to
highlight the value hiding within.
In future tutorials, Python will continue to emerge as a melting pot that will
be our central focus for querying Metadata, the repository database, and the
creation of .hyper extracts fueling our eventual impact analysis dashboards.
The no code approach to getting metadata
Without needing to write a script that authenticates into your Tableau Server
environment and fetches information, you can go to this URL to access your
metadata:
https://<your-tableau-server>.com/metadata/graphiql
You’ll be prompted to authenticate with your username and password as you
normally would, but instead of seeing the usual interface you will land on
the built-in GraphQL interface. By the way that is not a typo in the sample
link above. It is ‘graphiql’ with an ‘i’ in it.
Welcome to the GraphQL Metadata API sandbox
From here you can freestyle on building some basic GraphQL queries. Did I
say no code earlier? Don’t worry, you’ll be fine. Feel free to just copy and
paste these sample queries. If you’re the adventurous type, head over to the
Metadata API documentation to master all the things.
For example, running this basic query will fetch you all of the workbook
names, workbook IDs, and workbook owners on your site:
{
workbooks {
name
luid
}
}
owner {
name
email
}
The response will appear on the right half of your GraphQL interface in JSON
format. My output looked like this:
The hideous blue coloring is me blocking out my super secret email address.
Did you know you can connect Tableau Desktop directly to JSON files? Yep,
getting Metadata into a dashboard can be that easy. Just copy the JSON
output and paste it into a text file. Save the file with a .json extension, and
you’re set.
Below you’ll find the whole process in action, using a more advanced query
in place of the toy example provided above. The query can be found in this
Github Gist:
1
# workbooks
2
3
4
{
workbooks {
5
workbook_name: name
6
workbook_id: luid
7
workbook_project: projectName
8
views {
9
view_type: __typename
10
view_name: name
11
view_id: luid
12
}
13
upstreamTables {
14
upstr_table_name: name
15
upstr_table_id: luid
16
upstreamDatabases {
17
upstr_db_name: name
18
upstr_db_type: connectionType
19
upstr_db_id: luid
20
upstr_db_isEmbedded: isEmbedded
21
}
22
}
23
upstreamDatasources {
24
upstr_ds_name: name
25
upstr_ds_id: luid
26
upstr_ds_project: projectName
27
}
28
embeddedDatasources {
29
emb_ds_name: name
30
}
31
upstreamFlows {
32
flow_name: name
33
flow id: luid
33
o _ d:
34
flow_project: projectName
35
}
36
37
u d
}
}
tableau-server-metadata-api-workbook-db-assets hosted with ❤ by GitHub
view raw
Use this query to follow along.
After you store the resulting JSON data to a .json file, open Tableau Desktop
and connect to the file.
Make a new data connection and select the JSON file option
Select all the schemas available in the .json file and click ‘OK’.