Mastering Tableau REST API for BI Automation
Working with the REST API
Comparison of connection types: Username/Password vs Personal Access Token (PAT)
When you call the REST API, you must sign in to retrieve an authentication token. You can do that via username/password or a PAT.
In short, the username/password are the same as what you use for logging into the server. But you have to deal with the main rule: if your server role and access rights are limited to work with some content — you’ll be able to work with only that content via API as well.
PAT is a personal access token which you may issue from your account settings. When you create a token once, store it securely, because password changes for your account do not affect it until it’s revoked or expires. It’s ideal for automations or microservices.
Below are two short scripts illustrating both methods on Python using tableauserverclient (TSC) library (these were precisely the ones I used when starting out).
Authentication via Username/Password
Authentication via PAT
Practical REST API Usage
After authenticating, you can do a lot: list workbooks, add or remove users, download/upload workbooks, grab users’ permissions, etc. For example, to create a new user with required role on a server you may use such code in python:
I began automating routine tasks (like removing stale users or collecting usage data). The REST API is especially convenient for scenarios you might want to script repeatedly.