-
Can the REST API only be used with personalized access tokens or is it possible to retrieve a general token via a call like: |
Beta Was this translation helpful? Give feedback.
Answered by
grigoriev
Jul 25, 2024
Replies: 1 comment 2 replies
-
Hi @schlami , it's possible with the just released PDF-exporter v5.5.4. Example how to convert LiveDoc to PDF: function fetchRestAPI(resource, options) {
const polarionRestApiToken = top.getRestApiToken();
if (options === undefined) {
options = {};
}
if (options.headers === undefined) {
options.headers = new Headers();
}
if (options.headers instanceof Headers) {
options.headers.set("X-Polarion-REST-Token", polarionRestApiToken);
} else {
options.headers["X-Polarion-REST-Token"] = polarionRestApiToken;
}
return fetch(resource, options);
}
function createAndDownloadBlobFile(blob, fileName) {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}
function convertLiveDocToPDF(projectId, spaceId, documentName) {
fetchRestAPI("/polarion/pdf-exporter/rest/api/convert", {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/pdf'
},
body: JSON.stringify({
"projectId": projectId,
"locationPath": spaceId + "/" + documentName,
"documentType": "DOCUMENT",
"paperSize": "A4"
}),
})
.then(response => {
if (!response.ok) {
throw new Error('response was not ok');
}
return response.blob();
})
.then(blob => {
createAndDownloadBlobFile(blob, documentName + ".pdf");
})
.catch(error => {
console.error('error!', error);
});
}
convertLiveDocToPDF("elibrary", "Specification", "Administration Specification"); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
grigoriev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @schlami ,
it's possible with the just released PDF-exporter v5.5.4.
Example how to convert LiveDoc to PDF: