This example shows how to supply custom headers for JSON Database. First, create a new report instance:
<script type="text/javascript">
// Create a new report instance
var report = new Stimulsoft.Report.StiReport();
...
Then, in
onBeginProcessData
event handler add custom HTTP headers:
...
// In `onBeginProcessData` event handler add custom HTTP headers
report.onBeginProcessData = function (args) {
if (
args.database === "JSON" &&
args.command === "GetData" &&
args.pathData && args.pathData.indexOf("/reports/ProtectedDemo.json") >= 0
) {
// Add custom header to pass through backend server protection
args.headers.push({key: "X-Auth-Token", value: "*YOUR TOKEN*"});
}
};
...
After that, load report from URL and render it:
...
// Load report from url
report.loadFile("../reports/SimpleListWithProtectedJson.mrt");
// Render report
report.renderAsync(function () {
document.getElementById("savePdf").disabled = false;
});
...
Finally, export report to PDF format and save it to file:
...
// Export report to PDF format and save to file
function saveReportPdf() {
// Export to PDF
report.exportDocumentAsync(function (pdfData) {
// Get report file name
var fileName = report.reportAlias;
// Save data to file
Stimulsoft.System.StiObject.saveAs(pdfData, fileName + ".pdf", "application/pdf");
}, Stimulsoft.Report.StiExportFormat.Pdf);
}
</script>
In the screenshot below you can see the result of the sample code: