REST API Tutorial

Tableau Rest API Example Using Python

Summary of learning

This Rest API tutorial will show you how to use Python to access the Tableau API. The Tableau Server includes an application programming interface (API) that allows programmers to perform any task that is managed by tabcmd.

This Rest API tutorial will show you how to use Python to access the Tableau API. The Tableau Server includes an application programming interface (API) that allows programmers to perform any task that is managed by tabcmd.

Users can use the API to manage server resources such as users, workbooks, data connections, and other resources. We can also create new users or import them from Active Directory, publish workbooks, create, view, and delete data sources, and perform other server-side operations.

There are the following HTTP verbs allows into API –

  • GET – To fetch record from server.
  • POST – To create a new record into the server, The new data will send into payloads.
  • PUT – To update the record into the server based on ID, The payloads will hold updated data.
  • Delete – To delete records from the server using Rest API.

How To Access Tableau API in Python

I’m getting information from a user by using the Tableau API URI. The URI identifies the site, project, workbook, user, or other resources, You are retrieving, adding, updating, or deleting. To retrieve records from the server, we will use the GET HTTP method. The following is an example of URI syntax:


https://your-server/api/3.5/sites/site-id/groups/group-id/users

The URI holds the following information –

  • your-server – This is the name of Tableau Server or IP address.
  • site-id – It holds the site identifier value.
  • group-id – This is an ID for the group.

The site, groups, and other resources is a 16 hexadecimal values in the following format: 9a8b7c6d5-e4f3-a2b1-c0d9-e8f7a6b5c4d.

Let’s install Python dependency

In this application, we will use the requests package to handle HTTP requests. The request and flask packages can be installed with the following command –

pip install requests
pip install flask

How To Get Tableau Site Users

Let’s create tableu.py file and add the below code into this file. We’ll get data using tableau API.

from flask import Flask
from flask_restful import Resource, Api
from flask_cors import CORS
import requests

app = Flask(__name__)
CORS(app) ## To allow direct AJAX calls

@app.route('/getGroups', methods=['GET'])
def home():
   try:        
    headers = {'Tableau-Auth': 'tableau token', 'Content-Type': 'application/json'}
    url = "https://your-server/api/3.5/sites/site-id/groups/group-id/users";
    res = requests.get(url, headers=headers)

    return r.json()

   except Exception as e:
    print('unable to get groups.')
    print(e.strerror)

if __name__ == '__main__':
   app.run(debug = True)
If you have requirements that needs our attentioN

Please feel free to contact us

We would love to hear from you

Share with your network

Facebook
Twitter
LinkedIn
WhatsApp
Email

This tutorial is intended to cover all the essentials steps and insights to understand Tableau Rest API Example Using Python

Genislab Technologies

Learn further