5 Replies Latest reply on Jan 11, 2019 1:33 PM by Jeff D

    How do I create a custom portal for Tableau Online?

    varun pillai

      I am trying to connect to Tableau Online and embed the workbook on my website. I am able to use TableauServerClient to connect to Tableau Online, however I am not able to get a working ticket to display the VIZ on the page.

      The code works for workbooks on Tableau Public since it doesn't require any authentication. But for Tableau Online, both the TSC and the REST API both produce tokens which expire and cannot be used.

      Here is my code:


      Here is my HTML:

        <script type='text/javascript'
        <script type="text/javascript">
         var viz;


         //when the page has loaded, load the viz
         var vizDiv = document.getElementById('myViz');
         var vizURL = {{vizURL}}

         var options = {

         width: '640px',
         height: '700px',
         hideToolbar: true,
         hideTabs: true
         viz = new tableau.Viz(vizDiv, vizURL, options)


        <div id="myViz"></div>


      Here is my python code:

      from flask import Flask, render_template, json, request

      import tableauserverclient as TSC

      import requests

      import xml.etree.ElementTree as ET


      app = Flask(__name__)



      def index():

         # using TSC
         tableau_auth = TSC.TableauAuth('username', 'password', site_id="mysite")

        server = TSC.Server('https://10az.online.tableau.com')


        authtoken = server.auth_token


         # Using traditional rest api
         url = "https://10az.online.tableau.com/api/3.2/auth/signin"

         payload = "<tsRequest>\r\n  <credentials name=\"username\" password=\"password\" >\r\n  <site contentUrl=\"mysite\" />\r\n  </credentials>\r\n</tsRequest>"
         headers = {

         'Content-Type': "text/xml",
         'Cache-Control': "no-cache"

        response = requests.request("POST", url, data=payload, headers=headers)

        tree = ET.fromstring(response.text)

         for elem in tree.iter('{http://tableau.com/api}credentials'):


        authtoken = elem.attrib['token']



        vizURL = "https://10az.online.tableau.com" + "/trusted/" + authtoken + "/t/mysite/views/myview/myview?embed:=y";


         return render_template('test.html', vizURL=vizURL)


      if __name__ == "__main__":

        app.run(debug=True, threaded=True)



      Can you please help me with this issue soon.