I am trying to publish a workbook to the tableau REST API with Node and Axios. I have had success in the past using Python to publish to the API so I am familiar with the API in general.
The docs provided by Tableau give an example publishing with AJAX:
//Publish Workbook
function publishWorkbook() {
var form = new FormData();
form.append("request_payload", "<tsRequest><workbook name=\"restWorkbook\" ><project id=\"06ca4b01-f882-4f7a-b4b5-60eb8e8bff8f\" ></project></workbook></tsRequest>");
form.append("tableau_workbook", "PATH TO Workbook");
var settings = {
"async": true,
"crossDomain": true,
"url": url + "sites/" + siteid + "/workbooks?overwrite=true",
"method": "POST",
"headers": {
"x-tableau-auth": auth
},
"processData": false,
"contentType": false,
"mimeType": "multipart/mixed",
"data": form
}
$.ajax(settings).done(function(response) {
console.log(response);
});
}
This is my attempt to do the same thing with Axios (https://masteringjs.io/tutorials/axios/form-data):
function publishWorkbook(base_url, site_id, project_id, workbook_filepath, auth_token) {
const url = base_url + `sites/${site_id}/workbooks?overwrite=true`;
const formData = new FormData();
formData.append("request_payload", `<tsRequest><workbook name="test" ><project id="${project_id}"></project></workbook></tsRequest>`);
formData.append("data", fs.createReadStream(workbook_filepath));
const headers = formData.getHeaders();
headers["x-tableau-auth"] = auth_token;
return axios.post(url, formData, {headers:headers});
}
I am receiving a 406 error code. Inspecting the FormData shows me a dataSize: 0, which seems weird. Any thoughts? Thanks!