Tableau REST API Samples

repository·master·Indexed 19 days ago

https://github.com/tableau/rest-api-samples

A collection of Python and Java code samples and Postman collections for interacting with the Tableau REST API. Includes specialized Python CLI tools for managing Tableau Pulse, such as bulk-followers for metric subscriptions and a utility for updating Pulse user notification preferences, cadence, and grouping settings.

Tokens
4.5K
Snippets
10
Records
25
Agent score
66%

What's inside tableau-rest-api-samples

  1. Overview of bulk-followers capabilities

    master

    The bulk-followers Python CLI tool is designed for Tableau administrators to manage Pulse metric subscriptions at scale for both Tableau Server and Tableau Cloud.

    Key Capabilities:

    • Add Followers: Bulk subscribe users to Pulse metrics.
    • Remove Followers: Bulk unsubscribe users from metrics.
    • Batch Operations: Process multiple metrics and users in a single session.
    • Email-based Lookup: Use email addresses to identify users (the tool handles LUID conversion).
    • Flexible Authentication: Supports Personal Access Tokens (PAT) or username/password.
  2. Compile and Run the Java REST API Samples

    master

    Once the setup is complete and Tableau Server is running, use Apache Ant to build and execute the samples:

    1. Open a terminal or command prompt.
    2. Navigate to the parent folder of the sample code.
    3. Compile and download dependencies: Run the ant command.
    4. Execute the sample: Run the ant run command.
    ant
    ant run
  3. Requirements for Java REST API Samples

    master

    To use the Java samples in this repository, you must have the following tools installed:

    • Tableau Server: The target server for the API calls.
    • Java SDK 8: Required for compiling and running the code.
    • Apache Ant: Used for building and running the samples. Note that running 'Optional' steps in the Apache Ant guide is not required.
    • Apache Ivy: Used for dependency management. Follow the installation instructions included in the Ivy download package.
  4. Use bulk-followers to manage Pulse metric subscriptions

    master

    Run the bulk_manage_followers.py script to start an interactive session. The tool allows you to bulk add or remove followers from Tableau Pulse metrics using email addresses. The script will guide you through an interactive prompt to provide:

    1. Tableau server URL and site
    2. Authentication credentials (supports Personal Access Tokens (PAT) or username/password)
    3. Action (choose to add or remove followers)
    4. Metric IDs (provided as a comma-separated list)
    5. User emails (provided as a comma-separated list; the tool automatically converts these to LUIDs)
    python bulk_manage_followers.py
  5. Configure the script for Tableau Cloud vs. Tableau Server

    master

    Depending on your hosting environment, follow these configuration rules:

    Tableau Cloud

    • Server URL: Must include the pod name (e.g., https://10ay.online.tableau.com).
    • Authentication: Use Personal Access Tokens (PAT) if MFA is enabled.
    • Site Content URL: This is required and cannot be empty.
    • Note: Some sites may have user visibility restrictions.

    Tableau Server

    • Server URL: Use your server's accessible network URL.
    • Site Content URL: For the default site, leave this empty.
    • Authentication: Supports both PAT and username/password.
    • Note: Ensure the server is accessible from your network and you have permissions to access user lists.
  6. Use Pulse CLI tools for managing Tableau Pulse

    master

    The pulse/ directory contains Python-based CLI tools designed to manage Tableau Pulse via the REST API:

    • bulk-followers: Used to bulk add or remove followers from Pulse metrics.
    • user-preferences: Used to manage Pulse user notification preferences, including cadence, channels, and grouping.

    Detailed instructions for running these tools can be found in the respective subdirectories within pulse/.

  7. Prerequisites for using Tableau Webhooks Postman collection

    master

    Before using the Postman collection in this repository to access Webhooks methods in the Tableau REST API, ensure you have the following components ready:

    1. Tableau Site Administrator Access: You must have administrator privileges on the Tableau site.
    2. Site ID: The unique identifier for your Tableau site. You can retrieve this using the Tableau REST API or the Tableau Server Client.
    3. Personal Access Token (PAT): A PAT generated for the site to handle authentication.
    4. Webhook Destination: A valid https URL where Tableau will send the webhook payload. If you do not have a dedicated server, you can use public testing services such as:
      • https://webhook.site
      • https://postman-echo.com
      • https://requestbin.com/
      • A project on Glitch (see existing examples)
    5. Trigger Event: An event that will initiate the webhook call.
    6. Webhook Name: A unique name for your new webhook configuration.
  8. Get started with Tableau REST API samples

    master

    To use the samples in this repository, follow these steps:

    1. Clone the repository: Download the source code to your local machine.
    2. Select an API version: Choose the REST API version that matches your Tableau Server or Tableau Online version. You must configure the samples to use this specific version.
    3. Run samples: Execute the samples against your Tableau Server or Tableau Online instance.

    Note: The Java samples are written for Java 8 and are not compatible with Java 11 or Java 13.

    # Clone the repository
    git clone https://github.com/tableau/rest-api-samples.git
  9. Run Python REST API samples

    master

    All samples are executed via the command prompt or terminal. Each sample requires exactly two arguments: the server address (ensure there is no trailing slash) and the username.

    Command Syntax: python <sample_file_name>.py <server_address> <username>

    Important Configuration Notes:

    • API Version: The default API version is set to 3.5 (compatible with Tableau Server 2019.3). You can modify this version in version.py.
    • Tableau Server 9.0 Compatibility: If using Tableau Server 9.0, you must manually update the REST API namespace (xmlns) within each sample file as indicated by the comments in the code.
    python publish_workbook.py https://your-tableau-server.com my_username
  10. Manage Pulse user notification preferences

    master

    You can update Pulse notification settings for individual users or perform bulk updates for multiple users (via comma-separated emails).

    Note for Administrators: System administrators can update preferences for any user by providing the user's email. The script will automatically detect if you are updating yourself or another user and include the user_id field in the API request if necessary.

    Available Configuration Options

    Cadence Settings

    Controls notification frequency:

    • CADENCE_DAILY: Daily notifications
    • CADENCE_WEEKLY: Weekly notifications
    • CADENCE_MONTHLY: Monthly notifications

    Channel Preferences

    Configures delivery channels (Note: availability is managed automatically by Tableau and is read-only):

    • DELIVERY_CHANNEL_EMAIL: Email notifications
    • DELIVERY_CHANNEL_SLACK: Slack notifications
    • Status: Set to CHANNEL_STATUS_ENABLED or CHANNEL_STATUS_DISABLED.

    Metric Grouping Preferences

    Sets how metrics are grouped and sorted in Pulse:

    • Group By Options:
      • GROUP_BY_DEFINITION_NAME: Group by definition name
      • GROUP_BY_TIME_RANGE: Group by time range
      • GROUP_BY_RECENTLY_FOLLOWED: Group by recently followed metrics
      • GROUP_BY_DATASOURCE_LABEL: Group by data source label
    • Sort Order:
      • SORT_ORDER_ASCENDING: Ascending order
      • SORT_ORDER_DESCENDING: Descending order
    📅 Cadence: CADENCE_WEEKLY
    📧 Channel Preferences:
       1. Channel: DELIVERY_CHANNEL_EMAIL
          Status: CHANNEL_STATUS_ENABLED
    📊 Metric Grouping Preferences:
       Group By: GROUP_BY_DEFINITION_NAME
       Sort Order: SORT_ORDER_DESCENDING