Tableau’s REST API does not natively support exporting workbooks, images, or PDFs directly. However, you can achieve this using a combination of Tableau REST API and the Tableau Server Client (TSC) or the JavaScript API. Here’s how:
1. Export a Tableau Workbook (TWB or TWBX)
You can export a workbook using the REST API by downloading it from Tableau Server:
Endpoint:
GET /api/3.15/sites/{site_id}/workbooks/{workbook_id}/content
Steps:
1. Authenticate using Tableau’s REST API (/auth/signin).
2. Get Site ID & Workbook ID from /sites and /workbooks.
3. Download the Workbook using the content endpoint.
Example using Python:
import requests
TABLEAU_SERVER = "https://your-tableau-server"
TOKEN = "your-auth-token"
SITE_ID = "your-site-id"
WORKBOOK_ID = "your-workbook-id"
url = f"{TABLEAU_SERVER}/api/3.15/sites/{SITE_ID}/workbooks/{WORKBOOK_ID}/content"
headers = {"X-Tableau-Auth": TOKEN}
response = requests.get(url, headers=headers)
if response.status_code == 200:
with open("workbook.twbx", "wb") as file:
file.write(response.content)
print("Workbook downloaded successfully.")
else:
print("Failed to download workbook:", response.text)
2. Export Image or PDF using REST API
The REST API doesn’t support direct PDF/image export, but you can use the Tableau Views API:
Export Image (PNG)
GET /api/3.15/sites/{site_id}/views/{view_id}/image
Export PDF
GET /api/3.15/sites/{site_id}/views/{view_id}/pdf
Example in Python (Export Image):
VIEW_ID = "your-view-id"
url = f"{TABLEAU_SERVER}/api/3.15/sites/{SITE_ID}/views/{VIEW_ID}/image"
response = requests.get(url, headers=headers)
if response.status_code == 200:
with open("view.png", "wb") as file:
file.write(response.content)
print("Image exported successfully.")
else:
print("Failed to export image:", response.text)
Example in Python (Export PDF):
url = f"{TABLEAU_SERVER}/api/3.15/sites/{SITE_ID}/views/{VIEW_ID}/pdf"
response = requests.get(url, headers=headers)
if response.status_code == 200:
with open("view.pdf", "wb") as file:
file.write(response.content)
print("PDF exported successfully.")
else:
print("Failed to export PDF:", response.text)
Alternative: Tableau Server Client (TSC)
Tableau Server Client (TSC) is a Python library that simplifies these operations.
Install it:
pip install tableauserverclient
Example (Download Workbook):
import tableauserverclient as TSC
TABLEAU_SERVER = "https://your-tableau-server"
USERNAME = "your-username"
PASSWORD = "your-password"
SITE_ID = "your-site-id"
WORKBOOK_ID = "your-workbook-id"
server = TSC.Server(TABLEAU_SERVER, use_server_version=True)
auth = TSC.TableauAuth(USERNAME, PASSWORD, SITE_ID)
with server.auth.sign_in(auth):
workbook = server.workbooks.get_by_id(WORKBOOK_ID)
server.workbooks.download(workbook.id, filepath="workbook.twbx")
print("Workbook downloaded.")
Summary
Format
REST API
TSC Python SDK
Workbook (.twb/.twbx)
✅
✅
Image (.png)
✅
âŒ
✅
âŒ
If you’re working with Tableau Public, you can use Tableau’s JavaScript API for embedded views.
Let me know if you need help setting this up!