Supply Custom Headers for Json Database
Our sample projects and report templates can help you learn the basics of working with our products.When a report loads data from a protected JSON endpoint, you may need to send authentication headers.
Preparing the data. Read or create the data source, register it in the report dictionary, synchronize the schema, and render with the supplied records.
Preparing the data. Read or create the data source, register it in the report dictionary, synchronize the schema, and render with the supplied records.
const Stimulsoft = require('stimulsoft-reports-js');
const report = new Stimulsoft.Report.StiReport();
report.onBeginProcessData = function (args) {
if (args.database === "JSON" && args.command === "GetData" &&
args.pathData && args.pathData.endsWith("/ProtectedDemo.json")) {
args.headers.push({ key: "X-Auth-Token", value: "*YOUR TOKEN*" });
}
};
report.loadFile("SimpleListWithProtectedJson.mrt");
report.renderAsync(function () { report.saveDocumentFile("out.mdc"); });The onBeginProcessData event fires before each data request; its args.headers array lets you attach any HTTP headers, so a server-side report can authenticate to secured JSON or REST endpoints.