FOR BI PROS LEARN Tableau
Mixing Tableau APIs: interoperability between Official and undocumented APIs
March 30, 2015
6
, , ,

By reading the tableau forums it seems the new, completed Tableau 9.0 REST API has some gaps. In this particular example Takaya wanted to get the repository URL for a view (based on view id, which is returned from rest api). From the replies it seems he gave up and used the “undocumented api“, which is pretty shameful from new shiny API’s perspective.

But here comes the trick. You can login first with REST API, then get the repository URLs with the “undocumented” one (spoiler: this will be the example later in this post). Or you can logon with trusted authentication or RSA encrypted passwords on HTTP layer and use the REST API after then (to avoid clear text passwords on the network) as required in this forum post. You can mix things as you want. It seems, even if the common sense push us to rest api direction – use something for the complete functionality outside the API boundaries is a valid real-life requirement.

To show how this works I would use and extend my clojure api example from tableau developer forum.

As it contains some reusable parts, lets start with them. These functions manage the http calls and the basic XML responses.

Lines 1-7: First the namespace definition () with necessary requires to the libraries what we are going to use. clj-http for http invocation, data.xml and their zippers for easy xml parsing.

Lines 8-17: Construct URL to invoke. If we do not have session (passing a single host to the function) just concat host + “/api/2.0” + path, while if we already having a session put /sites/<siteid> into the path.

Lines 19-26: Get XML zipper from http-client response. (Get body, parse as XML string, create a zipper from it). Based on Korny’s excellent blog post.

Lines 28-38: Http client. It takes the http method (get, post, delete, etc.), host, path and http parameters. Based on the method name it will find the matching function by symbol name (=cool).

This is all we need as support for communicating with Tableau Server, not more than 40 lines of code. Without using one single variable.

Lets see, what we need to log on to the system:

We have two functions here, the first one create the ts-request XML file – it takes site, name and password and creates the XML file as tableau requires. Please note how easy to build XML files without even invoking one single string function.

Logon posts the request to the “/auth/signin” API path and builds a session map from the response.

That’s it. We are ready to test our thesis and check if we are able to perform actions in tableau server with this session or not.

To test, use the following code which:

  1. Logon with the logon-to-server function
  2. That will build the XML, post the server, parse the response and return with a session map
  3. Get the token from the session and print it. We will use this token as workgroup_session_id cookie value
  4. Invoke workbooks/Finance.xml for getting all information for Finance workbook. Method is get, we set only the workgrou_session_id cookie to that cookie value what got from REST Api logon
  5. Get views->view->repository-url XML path contents and print it

In code:

And the results:

Test mixed Tableau Server invocation

Calling multiple APIs, constructing and parsing the XMLs, within few lines of code, still, without any variables.

So how it will work from the opposite? Can we use trusted authentication or simple RSA based logon? Yes, both will work, in case you just need to use workgroup-session-id cookie as X-Tableau-Auth http header. As you do not need siteid in “undocumented” API, this is something, what you need lookup immediately by getting and parsing the value of “ api/2.0/sites/site-content-url?key=contentUrl “.

It seems we have solution for everything as we can mix different APIs with the same login data.

Was your use case covered? Let me know if you need something and you cannot find it in Tableau Server interfaces.

Tamás Földi

Tamás Földi

Director of IT Development at Starschema
Decades of experience with data processing and state of the art programming. From nuclear bomb explosion simulation to distributed file systems. ethical hacking, real time stream processing practically I always had a great fun with those geeky ones and zeros.
Tamás Földi
  • Maciek Darf Łazęcki

    Hi! I managed to generate cookie via with session_id and XSRF-Token using the undocummented api but cannot make any subsequent calls with those values in cookie only (403 error). Is there any way to bypass that using only JS?

    • Yossi

      Hey Maciek,

      I’m struggling with extracting the X-Session-ID (i.e. sessionid), how did you manage to retrieve it?

      • Maciek Darf Łazęcki

        Actually I didn’t as I was bound to front end languages. It’s fairly easy to get it using php or python. I ended up using Undocumented API. You can find my post here: http://meowbi.com/2017/10/23/tableau-fields-definition-undocumented-api/
        There’s a reference to Python solution.

        • Yossi

          Thanks for the prompt reply. i think that i’m looking for something else.. i’ve no issue extracting both “XSRF Token” and “Workgroup Session ID” using a Python code. However, i was unable to find a way to extract the sessionid (e.g. 92816A4A438248478A9E1E2300E4726A-1:0). why i need that? in order automate/script a download of a view (as CSV, PDF works well using tabcmd) the following link is triggered “https://tableau.xxxxx.com/vizql/t/xx/w/Pipeline/v/Details/exportcrosstab/sessions/92816A4A438248478A9E1E2300E4726A-1:0/views/8234017833420080962_16235592657524522848?charset=utf16&download=true&nodata=true”. note the string after “sessions”… this is is what i’m looking for 🙂

          • if you have some code available online I can have a look on it

          • Yossi

            I’ve the working code to get the API access token, “XSRF Token” and “Workgroup Session ID” but i’m missing the code/process how to get the (viz?) sessionid

Related items

/ You may check this items as well

Pasted image at 2018_01_09 04_59 PM

Python Experiments in Tableau 1. – Add live currency conversion to Tableau Dashboards using TabPy

By reading the tableau forums it seems the new, co...

Read more
Tableau Docker

HOWTO: Tableau Server Linux in Docker Container

By reading the tableau forums it seems the new, co...

Read more
Tableau Consistency Checker

Tableau Filestore Consistency Checker – How Repository Maps to Filestore

By reading the tableau forums it seems the new, co...

Read more