Exercise #4_01 | REST APIs and Tableau - Genie52/TCE19 GitHub Wiki

With the Tableau Server REST API you can manage and change Tableau Server resources programmatically, using HTTP. The API gives you simple access to the functionality behind the data sources, projects, workbooks, site users, and sites on a Tableau server. You can use this access to create your own custom applications or to script interactions with Tableau Server resources.

If you program in Python, you can also use the Tableau Server Client (TSC), a Python library for the Tableau Server REST API. Using the TSC library, you can manage and change many of the Tableau Server and Tableau Online resources programmatically.

REST API Resources | TSC Resources

Use the Tableau Server Client (TSC) library to increase your productivity as you interact with the Tableau Server REST API. With the TSC library you can do almost everything that you can do with the REST API, including:

  • Publish workbooks and data sources.
  • Create users and groups.
  • Query projects, sites, and more.

What is the most basic way to start with REST API and TSC Library? Well, you are in luck 'coz example is below:

# import TSC library in your python code so we can use it!
import tableauserverclient as TSC

# login to Tableau server and save the server information
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
server = TSC.Server('http://SERVER_URL')

# now that we are logged in we can start querying server resources like datasources
with server.auth.sign_in(tableau_auth):
    all_datasources, pagination_item = server.datasources.get()
    print("\nThere are {} datasources on site: ".format(pagination_item.total_available))
    print([datasource.name for datasource in all_datasources])

Now that we are all setup and ready lets look at the files we have for this exercise!

Open CMD, make sure Flask server is stopped (if you have it running from the previous exercise) go to folder C:\LabsTCE19\04 - REST APIs\ and run:

python 01-TSC-Finish.py

You should get something like this as result:

That looks like a lot of information! Where did it all came from? Well, let's look at the file!

Open 01-TSC-Finish.py in Atom and take a moment to go thru file, you will see numerous commented paragraphs with explanation what each one is doing. You will use that file as a source to copy the code to 01-TSC-Start.py file. It would be a good time now also to open that file in Atom.

The plan here is to add one by one those paragraphs of code so you can se exactly what each one is doing. Also its quite satisfying :). So, as you have now both files open (01-TSC-Finish.py and 01-TSC-Start.py) in Atom, start copy pasting paragraph by paragraph (they are numbered) from 01-TSC-Finish.py to 01-TSC-Start.py and as you copy one, just start the file in CMD to see result.

How to copy (just make sure code indentation is same as in finish file! Python is very sensitive on code positioning)

after you copy one paragraph - start the file in CMD (of course you should still be in the same folder - C:\LabsTCE19\04 - REST APIs)

python 01-TSC-Start.py

and with every additional paragraph of code you will see more and more information!

So now finally a little bit of Challenge!

I will show you what to do with the Portal Web Files - and you will do it alone!

MUAAHAHAHAHAHHAAAAAAaaaaaaa......