Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I'm working in a POC were i have a requirement to create a pixel-perfect report and call it on-demand based on user selections in an embedded sheet. The sheet will be available to authenticated users on a custom authenticator provider. The app has section access.
Reviewing the documentation , haven't found any information about compatibility with section access The only note is that is required to call the api using an authentication token and this token inherits the permission from the user it belongs. My assumption is correct ?
Also haven´t found much information or samples about using Reporting Service API to call a pixel-perfect template and generate a report.
So I'm looking for some answers about executing Reporting Service API on demand considering this scenario.
I'm also looking for some code snipets to call the API, check status of report generation and download the generated file, but didn´t found anything. Were can I found some examples ?
Thanks for helping !
Hi Pablo,
Could you please provide the final implementation including the adjustments you made? I'm looking for the same solution, trying to trigger the generation of a Reporting Service report (in my case an Excel file) from a mashup web page.
Thanks,
Ariel
Hi! I managed to solve this using a button extension called AncoreShare, which can run JavaScript code using the Webix library. Below is the code I implemented, which you can easily adapt for your mashup.
The key point is reusing the CSRF token from your session and sending it in the header when calling the API. This way, you don't need a bearer token, and the report generation automatically follows the user's security rules, including section access.
const hosturl = "{YourQlikCloudUrl}";
function getCookie(name) {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? match[2] : null;
}
function generateReport() {
const url = hosturl + "/api/v1/reports";
const headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"qlik-csrf-token":getCookie("_csrfToken"),
"credentials": "include",
};
const data = {
"type": "composition-1.0",
"output": {
"type": "pdfcomposition",
"outputId": "composition1",
"pdfCompositionOutput": {
"pdfOutputs": [{
"size": "A4",
"align": {
"vertical": "middle",
"horizontal": "center"
},
"resizeType": "autofit",
"orientation": "A"
}, {
"size": "A4",
"align": {
"vertical": "middle",
"horizontal": "center"
},
"resizeType": "autofit",
"orientation": "A"
}]
}
},
"definitions": {
"selectionsByState": {
"sel1": {
"$": [{
"values": [{
"text": "2021",
"isNumeric": false
}],
"fieldName": "OrderYear",
"defaultIsNumeric": false
}]
}
}
},
"compositionTemplates": [{
"type": "sense-sheet-1.0",
"senseSheetTemplate": {
"selectionStrategy": "failOnErrors",
"appId": "f6c2bb64-30a4-439a-ad41-c5f19c88d987",
"sheet": {
"id": "bLZwBC"
},
"selectionsByStateDef": "sel1"
}
}, {
"type": "sense-sheet-1.0",
"senseSheetTemplate": {
"selectionStrategy": "failOnErrors",
"appId": "f6c2bb64-30a4-439a-ad41-c5f19c88d987",
"sheet": {
"id": "uyXmT"
},
"selectionsByStateDef": "sel1"
}
}]
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
throw new Error("HTTP " + response.status);
}
const reportLocation = response.headers.get("Location");
if (!reportLocation) {
throw new Error("No 'Location' header found in response");
}
webix.message("Report started, checking status...");
checkReportStatus(reportLocation);
})
.catch(error => {
webix.message("Error generating report: " + error.message);
});
}
function checkReportStatus(reportUrl) {
const headers = {
//
};
let status = "";
const interval = setInterval(() => {
fetch(reportUrl, {
method: "GET",
headers: headers
})
.then(response => {
if (!response.ok) {
throw new Error("Status check failed: HTTP " + response.status);
}
return response.json();
})
.then(data => {
status = data.status;
webix.message("Status: " + status);
if (status === "done") {
clearInterval(interval);
webix.message("Report is ready!");
downloadReport(data.results[0].location);
}
})
.catch(error => {
clearInterval(interval);
webix.message("Error checking report status: " + error.message);
});
}, 1500);
}
function downloadReport(url) {
const link = document.createElement("a");
link.href = url;
link.download = "report.pdf";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
// Start the process
generateReport();