1 Reply Latest reply on May 15, 2018 5:10 AM by pinki sharma

    Query View PDF - REST API is not working

    pinki sharma

      Hi Guys,

       

      Hope you guys are doing well.

       

      I am using tableau python REST API version 3.0 and tableau server 2018.1.1 .

      I am trying to download pdf of a particular view.I get response 200 (OK) of  get pdf  REST API but pdf is not downloading.

       

      Thanks in advance !!

       

      Here is the code -

       

      import requests, json

       

      # NOTE! Substitute your own values for the following variables

      server_name = "localhost:8000"  # Name or IP address of your installation of Tableau Server

      user_name = "test"  # User name to sign in as (e.g. admin)

      password = "test"

      site_url_id = ""  # Site to sign in to. An empty string is used to specify the default site.

       

      signin_url = "http://{server}/api/3.0/auth/signin".format(server=server_name)

      payload = {"credentials": {"name": user_name, "password": password, "site": {"contentUrl": site_url_id}}}

      headers = {

          'accept': 'application/json',

          'content-type': 'application/json'

      }

       

      # Send the request to the server

      req = requests.post(signin_url, json=payload, headers=headers)

      req.raise_for_status()

       

      # Get the response

      response = json.loads(req.content)

       

      # Get the authentication token from the <credentials> element

      token = response["credentials"]["token"]

       

      # Get the site ID from the <site> element

      site_id = response["credentials"]["site"]["id"]

       

      print('Sign in successful!')

      print('\tToken: {token}'.format(token=token))

      print('\tSite ID: {site_id}'.format(site_id=site_id))

       

      # Set the authentication header using the token returned by the Sign In method.

      headers['X-tableau-auth'] = token

       

      # ... Make other calls here ...

      get_view_pdf_url = "http://localhost:8000/api/3.0/sites/a18ab9c9-c523-4848-9199-8c50e100ac36/views/e948dd8c-31b1-480a-8123-fecf47b1c682/pdf"

      reqPDF = requests.get(get_view_pdf_url, data=b'', headers={'x-tableau-auth': token})

      reqPDF.raise_for_status()

      print(reqPDF)

      print(reqPDF.content)

       

      # Sign out

      signout_url = "http://{server}/api/3.0/auth/signout".format(server=server_name)

      # Send the request to the server

      req.raise_for_status()

      req = requests.post(signout_url, data=b'', headers=headers)

      print('Sign out successful!')

       

       

      Regards,

      Pinki Sharma