Mixing Tableau APIs: interoperability between Official and undocumented APIs
March 30, 2015
, , ,

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

Related items

/ You may check this items as well

sync frelard

Tableau Extensions Addons Introduction: Synchronized Scrollbars

At this year’s Tableau Conference, I tried t...

Read more

Tableau External Services API: Adding Haskell Expressions as Calculations

We all have our own Tableau Conference habits.  M...

Read more
Scaling Tableau Image

Scaling out Tableau Extracts – Building a distributed, multi-node MPP Hyper Cluster

Tableau Hyper Database (“Extract”) is ...

Read more