---
schema_version: "1"
id: 3ac27b8130683c885f388a0e89e64a8a2e1994cfdfa3f2f6d55cb6cf5556074d
title: Python example
collection: tableau
version: current
locale: en-us
portal_url: https://docs.salesforce.com/tableau/current/en-us/api/explore-tableau/docs/example-python.md
canonical_url: https://help.tableau.com/current/api/explore-tableau/en-us/docs/example-python.html
source_site: help.tableau.com
content_type: documentation
content_hash: 8bc5964be75737ba6cff44f6ddbf4633957f9cd0667ab26177e8df87f58ba95e
description: Documentation for the Explore in Tableau API
---
# Python example

  

## Generating the JWT

A JSON Web Token (JWT) is a standard and secure way to transmit information between parties using JSON. General information about JWTs can be found at [jwt.io](https://jwt.io/).

This example uses the [PyJWT library](https://pyjwt.readthedocs.io/). (Other JWT libraries may import properly but cause errors when called.)

`jwt_generator.py`

```
import sys
import jwt
import datetime
import hashlib
import hmac

def main(api_key):
   if not api_key:
       print("Usage: python jwt_generator.py <api_key>")
       sys.exit(1)

   # Define the key
   key = api_key.encode()

   # Generate the JWT
   payload = {
       "iss": "Put any value",
       "sub": "Put any value",
       "iat": datetime.datetime.utcnow()
   }

   jwt = jwt.encode(payload, key, algorithm='HS256')

   print(f"Authorization: C2C:{jwt}")

if ~name~ == "~main~":
   if len(sys.argv) < 2:
       print("Usage: python jwt_generator.py <api_key>")
       sys.exit(1)
  
   api_key = sys.argv[1]
   main(api_key)
```

## Sending the request

Replace:

- `<API_KEY>` with the API key
- `<REGION>` with the Salesforce region
- `<BASE64_URLENCODED_TDS>` with the base64 URL encoded TDS

The URL in the script below is an example. Yours will be different, and will depend on the data provider string you’re assigned.

```
import requests

def make_api_call(jwt_token):
    api_url = "https://dev.api.salesforce.com/analytics/integration/explore-in-tableau/v1/upload-tds-content/example"

    # Create the JSON payload (base64-encoded TDS content here)
    json_payload = {
        "tdsContent": "<BASE64_URLENCODED_TDS>"
    }
    
    headers = {
        "Authorization": f"C2C:{jwt_token}",
        "x-salesforce-region": "<REGION>",
        "Content-Type": "application/json"
    }
    
    # Send the POST request
    response = requests.post(api_url, json=json_payload, headers=headers)
    
    return response

# Main execution
if __name__ == "__main__":
    api_key = "<API_KEY>"
    
    # Generate JWT token
    jwt_token = generate_jwt(api_key)
    
    # Make the API call with the JWT token
    response = make_api_call(jwt_token)
    
    # Check response status code and handle accordingly
    if response.status_code == 201:
        print("Resource created successfully (201). No response body.")
        location_header = response.headers.get("Location")
        if location_header:
            print(f"Location Header: {location_header}")
        else:
            print("Location Header not found.")
    else:
        print(f"Failed to call API. Status Code: {response.status_code}")
```