it will work or not. so test it.
const postImport = async function (stream, groupId, datasetDisplayName, isPaginatedReport) {
let url = null;
try {
console.log("* postImport *");
url = `https://api.powerbi.com/v1.0/myorg/groups/${groupId}/imports?datasetDisplayName=${datasetDisplayName}&${isPaginatedReport ? 'nameConflict=Abort' : 'nameConflict=CreateOrOverwrite'}`
const headers = await this.#powerBIAuth.getRequestHeader();
const form_data = new FormData();
form_data.append("value", stream);
function getLength() {
return new Promise((res, rej) => {
form_data.getLength((err, length) => {
if (err) {
return rej(err);
}
res(length);
})
})
}
const contentLength = await getLength();
const request_config = {
method: "post",
url: url,
headers: {
Authorization: headers.Authorization,
'Content-type': "multipart/form-data",
"Content-Length": contentLength
},
data: form_data
};
const response = await axios.request(request_config);
console.log('======================= postImport function completed');
return response
} catch (error) {
console.log("* post import error *");
if (error.response.data.error.code === "ReportWithDisplayNameForTheModelExists") {
this.url = "https://api.powerbi.com/v1.0/myorg/groups/${groupId}/imports?datasetDisplayName=${datasetDisplayName}&nameConflict=Overwrite";
const response = await this.postImport(stream, groupId, datasetDisplayName, isPaginatedReport)
return response
}
console.log(JSON.stringify(error));
if (error.response) {
throw new ErrorHandler(JSON.stringify(error.response.data.error), error.response.status);
} else {
throw error
}
}
};
The url variable value is not changing .
Обсуждают сегодня