Skip to content

Reports

The platform6.reports service allows generating and visualizing charts.

Read the user guide of the Reports service to discover its operating mode.

List the reports

This resource returns the list of the reports.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) list
platform6.request.user The email address of the user sending the message

Headers of the response

Header’s key Description
platform6.response.value The list of reports

Example

def cm = [ headers: [ 'platform6.request.action': 'list' ] ]

print p6.service.request('platform6.reports', cm).headers['platform6.response.value']

The response will be:

[
   {
      "name": "Invoice analysis - Failed invoice amount and count per month (bar and line charts, rolling 12 month)",
      "appKey": "",
      "description": {
         "EN": "Invoice analysis - Failed invoice amount and count per month (bar and line charts, rolling 12 month)"
      },
      "enabled": false,
      "contentMode": "NONE",
      "lastModifiedBy": "roxane.mace@amalto.com",
      "lastModifiedDate": 1530018148690,
      "revisionId": "1d9791822f820e495fbc7b8b97202282",
      "scriptId": "Reporting_Generate_All_DataSources (reports_auto_upgrade)",
      "template": "var myQuery = 'select * order by creationdate'\r\n\r\n\r\n ..."
   },
   {
      "name": "Invoice analysis - Failed invoice ratio per month (line charts, rolling 12 month)",
      "appKey": "",
      "description": {
         "EN": "Invoice analysis - Failed invoice ratio per month (line charts, rolling 12 month"
      },
      "enabled": false,
      "contentMode": "NONE",
      "lastModifiedBy": "roxane.mace@amalto.com",
      "lastModifiedDate": 1530018148758,
      "revisionId": "118eac4109263b8ef1ec5e30a822a113",
      "scriptId": "Reporting_Generate_All_DataSources (reports_auto_upgrade)",
      "template": "var myQuery = 'select * order by creationdate'\r\n\r\nvar query = new google.visualization.Query('${proxyrooturl}&access_token=${accesstoken}&table=ds_invoices_failed_ratio_period');\r\n\r\n\r\n// Apply query language statement..."
   },
   {
      "name": "Invoice analysis - Invoices amount split by status (pie chart, today)",
      "appKey": "",
      "description": {
         "EN": "Invoice analysis - Invoices amount split by status (pie chart, today)"
      },
      "enabled": false,
      "contentMode": "NONE",
      "lastModifiedBy": "roxane.mace@amalto.com",
      "lastModifiedDate": 1530018148770,
      "revisionId": "3c851af38d97ffa55015126c79b5982c",
      "scriptId": "Reporting_DataSource_Split_by_Customer (reports_auto_upgrade)",
      "template": "var myQuery = 'select *'\r\n\r\n\r\n    var query = new google.visualization.Query('${proxyrooturl}&access_token=${accesstoken}&table=ds_invoices_today_USD');\r\n\r\n    \r\n\r\n\r\n// Apply query language statement.\r\nquery.setQuery(myQuery);\r\n\r\n// Send the query with a callback function..."
   }
]

Get a report

Return the report by its identifier if it exists, otherwise, it returns null.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) get
id The identifier of the report (required)
platform6.request.user The email address of the user sending the message

Headers of the response

Header’s key Description
platform6.response.value The report

Example

def cm = [
    headers: [
        'platform6.request.action': 'get',
        'id': 'Invoice analysis - Invoices amount split by status (pie chart, today)'
    ]
]

print p6.service.request('platform6.reports', cm).headers['platform6.response.value']

If it exists it returns the item (see below), otherwise, it returns null.

{
   "name": "Invoice analysis - Invoices amount split by status (pie chart, today)",
   "appKey": "",
   "description": {
      "EN": "Invoice analysis - Invoices amount split by status (pie chart, today)"
   },
   "enabled": false,
   "contentMode": "NONE",
   "lastModifiedBy": "roxane.mace@amalto.com",
   "lastModifiedDate": 1530018148770,
   "revisionId": "3c851af38d97ffa55015126c79b5982c",
   "scriptId": "Reporting_DataSource_Split_by_Customer (reports_auto_upgrade)",
   "template": "var myQuery = 'select *'\r\n\r\n\r\n    var query = new google.visualization.Query('${proxyrooturl}&access_token=${accesstoken}&table=ds_invoices_today_USD');\r\n\r\n    \r\n\r\n\r\n// Apply query language statement.\r\nquery.setQuery(myQuery);\r\n\r\n// Send the query with a callback function.\r\nquery.send(handleQueryResponse);\r\n\r\nvar chart = null;\r\n\r\nfunction handleQueryResponse(response) {\r\n    if (response.isError()) {\r\n        alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());\r\n        return;\r\n    }\r\n\r\n    var data = response.getDataTable();\r\n\r\n    // Remove amounttotal column\r\n    data.removeColumn(1)\r\n    \r\n    var formatter = new google.visualization.NumberFormat(\r\n        {\r\n            groupingSymbol:',',\r\n            fractionDigits: 0\r\n        }\r\n    );\r\n    formatter.format(data, 0);\r\n    \r\n    var rows = data.getNumberOfRows()\r\n\r\n    for ( var y = 0 ; y < rows; y++ ) {\r\n        var tmp = data.getValue(y,0)\r\n        data.setValue(y, 0, tmp);\r\n    }\r\n\r\n    chart = new google.visualization.ChartWrapper({\r\n        \"chartName\": \"Chart 1\",\r\n        \"chartType\": \"PieChart\",\r\n        \"containerId\": \"#chartdivid#\",\r\n        \"dataTable\": data,\r\n        \"isDefaultVisualization\": false,\r\n        \"options\": {\r\n            \"title\": \"Invoice analysis - Today's invoices amount (USD) split by status\",\r\n            \"titleTextStyle\": {\r\n                \"bold\": true,\r\n                \"color\": \"#000\",\r\n                \"fontSize\": 16,\r\n                \"fontName\": \"Tahoma\"\r\n            },\r\n            \"booleanRole\": \"certainty\",\r\n            \"isStacked\": true,\r\n            \"legend\": \"right\",\r\n            \"sliceVisibilityThreshold\": 0,\r\n            \"animation\": {\r\n                \"duration\": 500\r\n            },\r\n            \"vAxis\": {\r\n                \"useFormatFromData\": true,\r\n                \"minValue\": null,\r\n                \"maxValue\": null,\r\n                \"logScale\": false,\r\n                \"viewWindow\": {\r\n                    \"min\": null,\r\n                    \"max\": null\r\n                }\r\n            },\r\n            \"hAxis\": {\r\n                \"titleTextStyle\": {\r\n                    \"bold\": false,\r\n                    \"color\": \"#000\",\r\n                    \"fontSize\": 12,\r\n                    \"fontName\": \"Tahoma\"\r\n                },\r\n                \"useFormatFromData\": true,\r\n                \"slantedText\": false\r\n            }\r\n        }\r\n    });\r\n\r\n    chart.draw();\r\n\r\n}\r\n\r\n\r\nwindow.onresize = function () {\r\n    if (chart!=null)\r\n        chart.draw();\r\n};\r\n"
}

Process a report

This resource processes a specific report.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) process
id The identifier of the report (required)
proxyRootUrl The proxy root (required)
accessToken The user’s access token (required)
platform6.request.user The email address of the user sending the message

Headers of the response

Header’s key Description
platform6.response.value The report’s template processed

Example

def cm = [
    headers: [
        'platform6.request.action': 'process',
        'id': 'Invoice analysis - Invoices amount split by status (pie chart, today)',
        'proxyRootUrl': 'https://devproxy.mycompany.io',
        'accessToken': 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpPU0UifQ'
    ]
]

print p6.service.request('platform6.reports', cm).headers['platform6.response.value']

The output will be the report’s script processed:

var myQuery = 'select *'

var query = new google.visualization.Query('https://devproxy.mycompany.io&access_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpPU0UifQ&table=ds_invoices_today_USD');

// Apply query language statement.
query.setQuery(myQuery);

// Send the query with a callback function.
query.send(handleQueryResponse);

var chart = null;

function handleQueryResponse(response) {
    if (response.isError()) {
        alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
        return;
    }

    var data = response.getDataTable();

    // Remove amounttotal column
    data.removeColumn(1)

    var formatter = new google.visualization.NumberFormat({
        groupingSymbol:',',
        fractionDigits: 0
    });
    formatter.format(data, 0);

    var rows = data.getNumberOfRows()

    for ( var y = 0 ; y < rows; y++ ) data.setValue(y, 0, data.getValue(y,0));

    chart = new google.visualization.ChartWrapper({
        "chartName": "Chart 1",
        "chartType": "PieChart",
        "containerId": "#chartdivid#",
        "dataTable": data,
        "isDefaultVisualization": false,
        "options": {
            "title": "Invoice analysis - Today's invoices amount (USD) split by status",
            "titleTextStyle": {
                "bold": true,
                "color": "#000",
                "fontSize": 16,
                "fontName": "Tahoma"
            },
            "booleanRole": "certainty",
            "isStacked": true,
            "legend": "right",
            "sliceVisibilityThreshold": 0,
            "animation": {
                "duration": 500
            },
            "vAxis": {
                "useFormatFromData": true,
                "minValue": null,
                "maxValue": null,
                "logScale": false,
                "viewWindow": {
                    "min": null,
                    "max": null
                }
            },
            "hAxis": {
                "titleTextStyle": {
                    "bold": false,
                    "color": "#000",
                    "fontSize": 12,
                    "fontName": "Tahoma"
                },
                "useFormatFromData": true,
                "slantedText": false
            }
        }
    });

    chart.draw();
}

window.onresize = function () {
    if (chart!=null) chart.draw();
};

If the report does not exist:

{
    "message" : "Unable to process the report's template! Template \"Invoice analysis - Invoices amount split by status (pie chart, today)\" not found. The quoted name was interpreted by this template loader: com.amalto.service.reports.ReportsService$ReportTemplateLoader@143343f.",
    "stackTrace" : [
        "com.amalto.b2auth.common.B2ResourceException: Unable to process the report's template! Template \"Invoice analysis - Invoices amount split by status (pie chart, today)\" not found. The quoted name was interpreted by this template loader: com.amalto.service.reports.ReportsService$ReportTemplateLoader@143343f.",
        "    at com.amalto.service.reports.ReportsService.processReportTemplate(ReportsService.java:169)",
        "    at com.amalto.service.reports.ReportsService.notifyRequestMessage(ReportsService.java:212)",
        "    at com.amalto.b2box.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)",
        "    at com.amalto.b2box.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)",
        "    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)",
        "    at java.util.concurrent.FutureTask.run(FutureTask.java:266)",
        "    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)",
        "    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)",
        "    at java.lang.Thread.run(Thread.java:748)",
        "Caused by: java.io.FileNotFoundException: Template \"Invoice analysis - Invoices amount split by status (pie chart, today) 2\" not found. The quoted name was interpreted by this template loader: com.amalto.service.reports.ReportsService$ReportTemplateLoader@143343f.",
        "    at freemarker.template.Configuration.getTemplate(Configuration.java:995)",
        "    at freemarker.template.Configuration.getTemplate(Configuration.java:907)",
        "    at freemarker.template.Configuration.getTemplate(Configuration.java:875)",
        "    at com.amalto.service.reports.ReportsService.processReportTemplate(ReportsService.java:162)",
        "    ... 8 more"
    ]
}

If a parameter is missing (in the example below it will be the proxyRootUrl):

{
    "message" : "Unexpected exception processing a report: the parameter 'proxyRootUrl' is missing.",
    "stackTrace" : [
        "com.amalto.b2box.core.api.B2boxException: Unexpected exception processing a report: the parameter 'proxyRootUrl' is missing.",
        "    at com.amalto.service.reports.ReportsService.notifyRequestMessage(ReportsService.java:201)",
        "    at com.amalto.b2box.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)",
        "    at com.amalto.b2box.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)",
        "    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)",
        "    at java.util.concurrent.FutureTask.run(FutureTask.java:266)",
        "    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)",
        "    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)",
        "    at java.lang.Thread.run(Thread.java:748)"
    ]
}