2 Replies Latest reply on Mar 10, 2017 4:40 PM by Hugh Nguyen

    Problem with uploading multipart content Workbook PS

    PEter Mueller



      I tried for serveral days to upload a workbook with PS to Tableau 9.3 Server.

      While all other rest queries like auth. and querying work fine, this one does not.

      I don't know what's the problem. I tried several different methods but even this one without using .net to build the body does not work.


      [String]$mimeType = [System.Web.MimeMapping]::GetMimeMapping("C:\Users\bla\Desktop\test.twb")
      Write-Host $mimeType
      [String]$strBody =("--BOUNDARY"+"Alpha"+"`r`n")
      $strBody+=("Content-Disposition: name=`"request_payload`"`r`nContent-Type: text/xml`r`n`r`n"+$tmpXML.InnerXml.ToString()+"`r`n")
      $strBody+=("Content-Disposition: name=`"tableau_workbook`"; filename=`"test.twb`"`r`nContent-Type: application/octet-stream`r`n`r`n"+($enc.GetString($buffer))+"`r`n")
      write-host $strBody

      Invoke-RestMethod -Uri ("https://tableauServerURL/api/2.2/sites/$($guidSiteID.ToString())/workbooks?workbookType=twb") -Method Post -Body $strBody -Headers $headers


      The resulting body is as follows:




      Content-Disposition: name="request_payload"


      Content-Type: text/xml



      <tsRequest><workbook name="TEST NAME"><project id="a8c4e137-28f8-4018-958d-eb5327f67796" /></workbook></tsRequest>




      Content-Disposition: name="tableau_workbook"; filename="test.twb"


      Content-Type: application/octet-stream


      Start content of twb file


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


      <!-- build 9300.16.0315.0125                                -->


      <workbook source-build='9.3.0 (9300.16.0315.0125)' source-platform='win' version='9.3' xmlns:user='http://www.tableausoftware.com/xml/user'>


      Further content of twb file







      I receive an error 500. Any idea what the problem is?





        • 1. Re: Problem with uploading multipart content Workbook PS
          Glen Robinson

          Hi Peter

          I had a few issues with this as well using PS.

          Few things that I found were.


          Ensure that the $strBody has the right formatting espicially around the carriage returns.

          The example on the REST API page shows the number of blank lines between the sections. These need to be the same as the example (if I remember correctly)



          Also, the boundary string needs to be declared in the header (See below)


          boundary-stringA string of characters that is guaranteed to be unique within the body of the request, and that is used to delimit sections of the request body. This value must be declared as a header that has this format:

          Content-type: multipart/mixed; boundary=boundary-string


          The other issue I found was that posting using Invoke-RestMethod worked fine with publishing XML content (TWB files), but failed when publishing Extracts or TWBX.

          So, I used the following instead


          $wc = New-Object System.Net.WebClient


          $wc.Headers.Add('ContentLength', $request_body.Length)

          $wc.Headers.Add('Content-Type', 'multipart/mixed; boundary=6691a87289ac461bab2c945741f136e6')

          $response = $wc.UploadString($url ,'POST', $request_body)


          Hope that that this helps


          All the best


          • 2. Re: Problem with uploading multipart content Workbook PS
            Hugh Nguyen

            The vizportal logs may provide some insight as to what's going on. If not, you can enable debug mode and reproduce the issue.