mstr-report-data-service
Version:
A Node function for calling Microstrategy's reportDataService task and returning the payload as JSON.
54 lines (50 loc) • 2 kB
JavaScript
import request from 'request-promise'
import parseMstrResults from './parseMstrResults'
/**
* The reportDataService function.
* @param {Object} args Request arguments object.
* @param {String} args.user Username.
* @param {String} args.pass Password of user.
* @param {String} args.reportID reportID of the report you want to run.
* @param {String} args.server Server name.
* @param {String} args.project Project name.
* @param {String} args.url Url of your Microstrategy instance.
* @param {String} [args.port] Server port.
* @returns {Promise} Resolved promise containing report data.
*/
function reportDataService(args) {
return new Promise((resolve, reject) => {
// error handling;
let errCount = 1;
let err = ['url', 'pass', 'project', 'server', 'user', 'reportID'].reduce((acc, prop, idx) => {
return !args.hasOwnProperty(prop) ? acc.concat(`Error [${errCount++}]: ${prop} is undefined.`) : acc
}, []).join('\n')
if (err.length > 0)
return reject(err)
request({
method: 'GET',
url: args.url,
qs: {
taskId: 'reportDataService',
password: args.pass,
port: args.port || '0',
project: args.project,
server: args.server,
userid: args.user,
reportID: args.reportID, // report id, in MSTR right click on report > properties
styleName: 'ReportDataVisualizationXMLStyle',
taskContentType: 'xml',
taskEnv: 'xml'
}
})
.then(parseMstrResults)
.then(body => {
resolve(body)
})
.catch(err => {
reject(err)
})
})
}
export default reportDataService
module.exports = reportDataService