I am trying to generate a JWT and using it to sign-in to Tableau Cloud using REST API. My code used to work, but is not since a few days, and its throwing error (16) and 401001. I am using Connected Apps Direct Trust for REST API authentication. Please also note that I am the Site Administrator Creator of my site, and using "Initial Google" for login into Tableau account.
As per the official documentation, its most likely related to exp or sub claim, and I have verified that all the information I am providing is correct. The Connected App is enabled, and its details are also correct. Here's my Python code:
import datetimeimport uuidimport jwtimport requests# =========================# JWT CONFIG# =========================BASEURL = "https://10ax.online.tableau.com"SITE = "userful"# =========================# JWT CONFIG# =========================CLIENT_ID = "XXX"SECRET_ID = "YYY"SECRET_VALUE = "ZZZ"USER = "bhavyai.gupta@userful.com"AUDIENCE = "tableau"SCOPES = [ "tableau:views:embed"]# =========================# GENERATE JWT# =========================current_time = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=5)token = jwt.encode( payload={ "iss": CLIENT_ID, "exp": current_time + datetime.timedelta(minutes=5), "jti": str(uuid.uuid4()), # "nbf": int((datetime.datetime.now(datetime.UTC) - datetime.timedelta(seconds=5)).timestamp()), "iat": datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(minutes=2), "aud": AUDIENCE, "sub": USER, "scp": SCOPES, }, key=SECRET_VALUE, algorithm="HS256", headers={ "kid": SECRET_ID, "iss": CLIENT_ID, "alg": "HS256" })print(f'JWT: {token}')# =========================# TABLEAU SIGN-IN REQUEST# =========================url = BASEURL + "/api/3.28/auth/signin"headers = { "Accept": "application/json", "Content-Type": "application/json"}payload = { "credentials": { "jwt": token, "site": { "contentUrl": SITE } }}response = requests.post(url, json=payload, headers=headers)# =========================# RESPONSE HANDLING# =========================print(f"\nStatus Code: {response.status_code}")try: print(f"Response JSON: {response.json()}")except ValueError: print(f"Response Text: {response.text}")
The exact
error
response I am receiving is this:
Status Code: 401
Response JSON: {'error': {'summary': 'Signin Error', 'detail': 'Error signing in to Tableau Server (16)', 'code': '401001'}}
Any help is greatly appreciated. Thank you!!!
#Tableau APIs & Embedding
Hi, it seems it is something related to the pod 10ax.online.tableau.com.
I have tested the code in other pods and it is working without problems. I tested two sites in the 10ax pod, and I could not sign in.
In this case, I suggest you to create a support case to the Tableau/Salesforce Team
https://help.salesforce.com/s/casesThat way, support team will be able to investigate the problem.
If this post resolves the question, would you be so kind to "Accept this Answer"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Tableau Ambassador