2 Replies Latest reply on Jan 17, 2019 9:13 AM by Ryan Goodman

    Using REST API without Site ID

    Ryan Goodman

      I am working on self hosted Tableau server where the admin did not setup sites upon install. So essentially the entire enterprise is running on the default site.

       

      The API docs explains what to do (not clearly) if there isn't a site:

       

        <site contentUrl="" />
      

       

      Now that I have authenticated successfully, I am stuck on a simple method to request workbooks:

       

      https://tableau.merchantscap.com/api/2.8/sites/{site-id}/workbooks/

       

      What I can't figure out is what to put in for the site-id when the enterprise install is not using sites?

       

        • 1. Re: Using REST API without Site ID
          Lewis Wong

          After you sign in by rest api, the response body contains the site id.

          https://onlinehelp.tableau.com/v2018.2/api/rest_api/en-us/help.htm#REST/rest_api_ref.htm#Sign_In%3FTocPath%3DAPI%2520Ref…

          Response Body

          <tsResponse>
          <credentials token="authentication-token" >
          <site id="site-id" contentUrl="content-url" />
          <user id="user-id-of-signed-in-user" />
          </credentials>
          </tsResponse>

           

           

          Extracting the sample code from https://onlinehelp.tableau.com/v10.0/api/rest_api/en-us/help.htm#REST/rest_api_samples.htm

          you can get the site id in below red color code

           

           

          def sign_in(name, password, site=""):

              """

              Signs in to the server specified in the global SERVER variable.

           

           

              'name'    is the name (not ID) of the user to sign in as.

                        Note that most of the functions in this example require that the user

                        have server administrator permissions.

              'password' is the password for the user.

              'site'    is the ID (as a string) of the site on the server to sign in to. The

                        default is "", which signs in to the default site.

           

           

              Returns the authentication token and the site ID.

              """

              url = SERVER + "/api/2.3/auth/signin"

           

           

              # Builds the request

              xml_payload_for_request = ET.Element('tsRequest')

              credentials_element = ET.SubElement(xml_payload_for_request, 'credentials', name=name, password=password)

              site_element = ET.SubElement(credentials_element, 'site', contentUrl=site)

              xml_payload_for_request = ET.tostring(xml_payload_for_request)

           

           

              # Makes the request to Tableau Server

              server_response = requests.post(url, data=xml_payload_for_request)

              if server_response.status_code != 200:

                  print(server_response.text)

                  sys.exit(1)

              # Reads and parses the response

              xml_response = ET.fromstring(_encode_for_display(server_response.text))

            

              # Gets the token and site ID

              token = xml_response.find('t:credentials', namespaces=xmlns).attrib.get('token')

              site_id = xml_response.find('.//t:site', namespaces=xmlns).attrib.get('id')

              user_id = xml_response.find('.//t:user', namespaces=xmlns).attrib.get('id')

              return token, site_id, user_id

           

          Hope it helps,

          Lewis

          • 2. Re: Using REST API without Site ID
            Ryan Goodman

            I didn't even think to look in the authentication response for the Site ID and there it was right in front of my nose!

             

            Thank you!