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.