2 Replies Latest reply on Aug 12, 2015 1:22 PM by Hugh Nguyen

    REST API Publish Datasource problems

    Drew Oldag

      Hi all,


      I'm trying to publish datasources programmatically using the REST API POST request. The URL I'm pinging is the following:



      The request headers look like the following:

      headers = {

          'x-tableau-auth': "<the token from successfully signing in>",

          'content-type': "application/xml",

          'boundary': "poopfish"


      My request body looks like the following:


      Content-Disposition: name="request_payload"

      Content-Type: text/xml




          <datasource name="headcount" >

              <project id="<The default project ID>" />




      Content-Disposition: name="tableau_datasource"; filename="headcount.tds"

      Content-Type: application/octet-stream


      <?xml version='1.0' encoding='utf-8' ?>


      <datasource formatted-name='sqlserver.42139.631334074100' inline='true' source-platform='mac' version='9.0' xmlns:user='http://www.tableausoftware.com/xml/user'>

        <!-- build 9000.15.0318.1720                                -->

        <repository-location id='Headcount' path='datasources' revision='1.0' />

        <layout dim-ordering='alphabetic' dim-percentage='0.5' measure-ordering='alphabetic' measure-percentage='0.4' show-structure='true' />





      I'm using Postman, as suggested by Tableau tech support to assemble my request. I'm able to successfully login and perform other trivial requests, but POSTing a datasource always results in the following error message:

      <?xml version="1.0" encoding="UTF-8"?>

      <tsResponse xmlns="http://tableausoftware.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableausoftware.com/api http://tableausoftware.com/api/ts-api-2.0.xsd">

          <error code="400000">

              <summary>Bad Request</summary>

              <detail>Payload is either malformed XML or incomplete</detail>





      Just curious if anyone else has run into this problem and found a way around it, or if there is something that I'm doing that is obviously incorrect here. (Possible problems include a lack of content-length in the header, the fact that the datasource is a .tds file, or perhaps incorrect encoding of the datasource body?) I'm taking any and all suggestions at this point


      Thanks in advance!

        • 1. Re: REST API Publish Datasource problems
          Russell Christopher

          I don't think postman will work for you since you need to post a multi-part form. It's OK for more simple stuff, but not for more complex work like publishing.


          I also don't see you doing anything above that TELLS tableau you're about to POST  multi-part/mixed content via the Content-Type header.  Your best bet is to use a library someone else has made which knows how to do multi-part posts can can automatically handle calculating the content-length. If you get that last part wrong, you'll almost always get failures.


          Here's an example that might get you going:


          Multipart/mixed POST to Tableau's REST api via NodeJS

          • 2. Re: REST API Publish Datasource problems
            Hugh Nguyen

            A bit late to this. To publish a resource, be sure that the content type in the header is set to "multipart/mixed; boundary=poopfish." The rest of the call looks to be ok. Content-length is not necessary as Postman will automatically fill that in. Depending on the datasource, you may also need to specify the connection credentials to the database in the tsrequest.