Spanish Total.js
Français
Documentation Pour les agents IA
Sommaire

Reports API

Read the list of reports and their data over HTTP with a token.

.md Site web

Cette page n’est pas encore traduite. Tu lis l’original.

Sur cette page

Other programs can list your reports and load their data over HTTP. The API is off until you turn it on in the config file.

Turn it on

  1. Add these keys to the file config, with your own long random token:
api                 : true
token               : 3f9c0d1e8b7a4c2f9e6d5a4b3c2d1e0f
  1. Restart Dashboard.

Send the token with every request, in the header x-token or in the query argument token. Without the right token, or while the API is off, the API answers 401: Unauthorized.

Private reports are not listed and cannot be loaded through the API.

List reports

GET /reports/ returns the reports with their fields and their dynamic filters.

curl -H 'x-token: 3f9c0d1e8b7a4c2f9e6d5a4b3c2d1e0f' http://localhost:8000/reports/
[
    {
        "id": "JasoWU1dx60f",
        "name": "Sales by region",
        "category": "Sales",
        "filter": [],
        "fields": [
            { "id": "x1jkk54k", "name": "Region", "datatype": "string" },
            { "id": "amount", "type": "sum", "name": "Amount", "datatype": "number" }
        ],
        "chart": true,
        "x": "x1jkk54k",
        "y": "amount",
        "series": ""
    }
]

Load a report

POST /reports/ with the id of the report runs it and returns its fields and rows.

curl -X POST -H 'x-token: 3f9c0d1e8b7a4c2f9e6d5a4b3c2d1e0f' -H 'Content-Type: application/json' \
    -d '{"id":"JasoWU1dx60f"}' http://localhost:8000/reports/
{
    "fields": [
        { "id": "x1jkk54k", "name": "Region", "datatype": "string" },
        { "id": "amount", "name": "Amount", "datatype": "number", "type": "sum", "format": 2 }
    ],
    "rows": [
        { "x1jkk54k": "West", "amount": 61627.42 },
        { "x1jkk54k": "North", "amount": 61365.73 },
        { "x1jkk54k": "South", "amount": 60752.96 },
        { "x1jkk54k": "East", "amount": 57640.19 }
    ]
}

To set the values of dynamic filters, add "filter": [{ "id": "<field id>", "value": "<value>" }] to the body.

Load the chart data

Add "chart": true to load the chart data of a report with Enable chart view. The answer is a list of series with points x and y:

[
    {
        "id": "JasoWU1dx60f",
        "name": "Sales by region",
        "icon": "ti ti-globe",
        "color": "#34A853",
        "data": [
            { "x": "West", "y": 61627.42 },
            { "x": "North", "y": 61365.73 },
            { "x": "South", "y": 60752.96 },
            { "x": "East", "y": 57640.19 }
        ],
        "format": "{0} EUR",
        "decimals": 0
    }
]

A report with Series for returns one series for each value of that field.

An unknown or private report answers 404: Not Found.

Fabriqué en Europe