Running a Report through the REST API (JavaScript)
Our sample projects and report templates can help you learn the basics of working with our products.A Server report can be run and shared from browser JavaScript by working with a report snapshot through REST.
Log in, run into a snapshot, share it.
How it works. Plain
Log in, run into a snapshot, share it.
function RunReport() {
var sessionKey = Connect(); // GET /1/login with x-sti-UserName/Password headers
// Create a snapshot
var snap = new XMLHttpRequest();
snap.open('POST', 'http://localhost:40010/1/reportsnapshots', false);
snap.setRequestHeader('x-sti-SessionKey', sessionKey);
snap.send(JSON.stringify({ Ident: 'ReportSnapshotItem', Name: '001', Expires: expires }));
var snapshotKey = JSON.parse(snap.responseText).ResultItems[0].Key;
// Run the template into the snapshot
var run = new XMLHttpRequest();
run.open('PUT', 'http://localhost:40010/1/reporttemplates/' + reportKey + '/run', false);
run.setRequestHeader('x-sti-SessionKey', sessionKey);
run.setRequestHeader('x-sti-DestinationItemKey', snapshotKey);
run.send();
// Share the snapshot and open its public URL
// PUT /1/items/{snapshotKey}/share -> GET .../share -> location.href = ResultUrl
}Connect()— GET/1/loginwith credential headers, returning theResultSessionKey.POST /reportsnapshots→/reporttemplates/{key}/run→/items/{key}/share— snapshot, run, then share for a public URL.
How it works. Plain
XMLHttpRequest calls chain the Server's REST endpoints, so a browser page can run and publish a report with no backend of its own.