I am the happiest boy in the whole world. I just discovered that I have internet access available during my entire flight between Chicago and Tokyo. I also have a whole row of seats to myself. There’s an idiot grin on my face, and I’m probably making my fellow passengers uncomfortable.
Whatever, I’m going to get some serious geek on, starting now.
The not-new-but-super-improved REST API In Tableau Server 9 now allows you to do things like publish workbooks and data sources, among other things. These activities require that you POST both:
- An <tsRequest> XML payload which describes the “file” you’re about to upload
- The body of the “file” itself (twb, tde, tds)
I did not find this particularly straight forward using NodeJS. I attempted to use the NodeJS request module and found that it automatically set Transfer-Encoding to chunked. Not good, because our API expects Content-Length to be set for the entire request body. Use this mechanism out of the box and Tableau will actually throw an exception like:
500 Internal Server Error If you are the administrator of this website, then please read this web application’s log file and/or the web server’s log file to find out what went wrong
I also tried manually crafting a POST using http and string concatenation but had a devil of a time calculating Content-Length myself.
Turns out the Form-Data module is perfect of this work. To save you some time, here’s an example of using it to publish a TDE to Tableau Server via the REST API:
Actual Source here in gist:
https://gist.github.com/russch/f77f95e13d2fbc698a1a
..or in GitHub: