2 Replies Latest reply on Apr 21, 2017 3:01 PM by Chris Sommers

    Download workbook with Python -- Rest API

    Chris Sommers

      Hi all,

       

      I'm new to Python and the REST API.  What I'd like to do is search a site for workbooks with a specific tag and then download them to a specific folder.  I figured out all of the other functions I need from Tableau's samples but I need help with the syntax for downloading a file with the REST API.

       

      I've built below as a starting point.  I'm not sure how to incorporate "Content Disposition Header" as referenced in Tableau's documentation.

       

      Download a Workbook:

      http://onlinehelp.tableau.com/v10.0/api/rest_api/en-us/help.htm#REST/rest_api_ref.htm#Download_Workbook%3FTocPath%3DAPI%…

       

      def download_workbook():
          """
          Downloads a server workbook to a specified file location.
          """
      
      
          
          file_path ='C:\\Users\\chsommer\\Desktop\\Test.twbx' #File path for downloaded file
          url = SERVER + "/api/2.3/sites/{0}/workbooks/{1}/content".format(SITE_ID, workbook_id)
          print(url)
          server_response = requests.get(url, headers={"x-tableau-auth": TOKEN})
          if server_response.status_code != 200:
              print(_encode_for_display(server_response.text.encode))
              sys.exit(1)
      

       

       

      Any help would be greatly appreciated!

       

      Chris