I was trying to upload a workbook to tableau using Tableau Rest API and Nodejs but i keep getting this error;
Error uploading the workbook: { error: { summary: 'Bad Request', detail: "There was a problem publishing the file 'Test.twbx'.", code: '400011' } }
Here is my code below;
`async function uploadWorkbook(
serverUrl: string,
authToken: string,
siteId: string,
workbookName: string,
projectId: string,
workbookContent: Buffer
): Promise {
console.log(serverUrl);
const wkBookcontent = await fs.readFile(src/download/${workbookName}.twbx
);
const boundary = generateBoundary();
const CRLF = “rn”; // Carriage Return Line Feed
// Construct the body of the request
const body = [
--${boundary}
,
‘Content-Disposition: form-data; name=”request_payload”‘,
“Content-Type: text/xml”,
“”,
<tsRequest> <workbook name="${workbookName}"> <project id="${projectId}"/> </workbook> </tsRequest>
,
“”,
--${boundary}
,
Content-Disposition: form-data; name="tableau_workbook"; filename="${workbookName}.twbx"
,
“Content-Type: application/octet-stream”,
“”,
${wkBookcontent}
,
“”,
--${boundary}--
, // End of multipart message
].join(CRLF);
// Set up headers for the request
const headers = {
“Content-Type”: multipart/mixed; boundary=${boundary}
,
“X-Tableau-Auth”: authToken,
Accept: “application/json”,
“Content-Length”: Buffer.byteLength(body),
};
try {
const response = await axios.post(
${serverUrl}/api/${VERSION}/sites/${siteId}/workbooks?workbookType=twbx&overwrite=true
,
body.toString(),
{ headers }
);
console.log(“Upload completed”, response.data);
} catch (error: any) {
console.error(
“Error uploading the workbook:”,
error?.response?.data || error.message
);
throw error;
}
}`