1
$\begingroup$

I am trying to query the Tableau REST API using Wolfram. I have been able to send all the other types of HTTPRequest to it without issues but for some reason whenever the Body is multipart with mixed types separated by boundary I can't get it to work.

My request is as follows:

HTTPRequest[ $server<>"/api/3.22/sites/"<>$site<>"/workbooks?workbookType=twb&overwrite=true", <| "Method"->"POST", "Headers"-><|"X-Tableau-Auth"->$token,"Content-Type"->"multipart/mixed; boundary="<>$boundary,"Accept"->"application/json"|>, "Body"->StringRiffle[{ "--"<>$boundary, "Content-Disposition: name=\"request_payload\"", "Content-Type: text/xml", ExportString[XMLElement["tsRequest",{},{ XMLElement["workbook",{ "name"->$workbook, "showTabs"->"false", "description"->"This is a test workbook!" },{ XMLElement["views",{},{ XMLElement["view",{"name"->$view,"hidden"->"true"},{}] }], XMLElement["project",{"id"->$project},{}] }] }],"XML"], "--"<>$boundary, "Content-Disposition: name=\"tableau_workbook\"; filename=\""<>FileNameTake@$file<>"\"", "Content-Type: application/octet-stream", Import[$file,"Text"], "--"<>$boundary<>"--" }, "\n" ], "Expect"->"100-continue", "Content-Length"->ToString@StringLength@Import[$file,"Text"] |> ] 

I keep getting the error:

{"error":{"summary":"Bad Request","detail":"Payload is either \ malformed or incomplete (Could not parse multipart servlet request; \ nested exception is \ org.apache.commons.fileupload.FileUploadException: Header section has \ more than 10240 bytes (maybe it is not properly \ terminated))","code":"400000"}} 

Please help this is a critical piece that is breaking my workflow. Please suggest any changes and I can make as many attempts to get it to work.

I am not sure how to send the content of the file, I assume this Import[$file,"Text"] is not right or Wolfram is messing up the multipart request somehow.

$\endgroup$

1 Answer 1

2
$\begingroup$

I suspect the issue is that there is no blank line separating the headers from the body within each of the subparts. For example:

 ... "Body"->StringRiffle[{ "--"<>$boundary, "Content-Disposition: name=\"request_payload\"", "Content-Type: text/xml", "", (* <---- add this blank line *) ExportString[XMLElement["tsRequest",{},{ ... 

Also, verify that the lines are being separated by both a carriage-return and linefeed as required by HTTP. Depending upon your platform, "\n" might only expand to linefeed and some servers are sensitive to that.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.