Skip to main content

I have the Tableau API doc but I  am not succeeding in making a successful API call using python.   Can someone jump start me  and give me an example on any API python sample code ? 

 

#Tableau APIs & Embedding

4 answers
  1. Mar 17, 7:59 PM

    @Sami Ahmad

     

    Hi, you may use:

    import jwt

    import tableauserverclient as TSC

    import datetime

    import uuid

    Client_id = "f27a043b-c771-4b18-a1a1-007e120293a3"

    SecretValue = "nijAJ5p"

    SecretID = "aaa0e3"

    siteId = ''

    token = jwt.encode(

    {

    "iss": Client_id,

    "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=10),

    "jti": str(uuid.uuid4()),

    "aud": "AHMADSA",

    "sub": "dmartinez@modux.co",

    "scp": ["tableau:content:read","tableau:workbooks:*","tableau:projects:*","tableau:datasources:*"]

    },

    SecretValue,

    algorithm="HS256",

    headers={

    'kid': SecretID,

    'iss': Client_id

    }

    )

    print(token)

    server = TSC.Server('https://tableau-qa.park-edw.com')

    tab_auth = TSC.JWTAuth(token,site_id=siteId)

    with server.auth.sign_in(tab_auth):

    print("signed in")

    workbooks, paginator = server.workbooks.get()

    for wb in workbooks:

    print(wb.name)

     

    Basically you need the tableau:content:read in the scopes: 

    https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_workbooks_and_views.htm#query_workbooks_for_site

     

    And in the auth object site_id=siteId

     

    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 

0/9000