Technical Tip: How to run a report on FortiAnalyzer via API
Description
This article describes how to run a report from FortiAnalyzer using the JSON RPC API.
Scope
FortiAnalyzer.
Solution
FortiAnalyzer allows reports to be executed programmatically using the JSON RPC API.
In the GUI, reports are generated from predefined report or custom report layouts. The same process can be triggered via API by referencing the report layout ID and initiating a run task.
Using the API, the same information can be retrieved programmatically. Review Technical Tip: Using FortiManager/FortiAnalyzer API to understand how to use the API on FortiAnalyzer.
Â
Retrieve available report layouts.
First, query the available report layouts to obtain the layout-id:
Request:
{
"id": "1",
"jsonrpc": "2.0",
"method": "get",
"params": [
{
"apiver": 3,
"url": "/report/adom/root/config/layout/",
"fields": ["layout-id", "title"]
}
],
"session": "sessionid"
}
Response:

'layout-id' values can be found for the desired report from the response.
Run the report.
After choosing the report, type the correct layout ID and run it.
Request:
{
"id": "string",
"jsonrpc": "2.0",
"method": "add",
"params": [
{
"apiver": 3,
"schedule": "1",
"schedule-param": {
"device": "all",
"display-table-contents": 1,
"include-coverpage": 1,
"layout-id": 5,
"resolve-hostname": 0,
"time-period": "last-7-days"
},
"url": "/report/adom/root/run"
}
],
"session": "session-id"
}
Response:
{
"jsonrpc": "2.0",
"id": "string",
"result": {
"tid": "8613d6be-71ad-11f1-bb50-006272610101"
}
}Report generation status can be checked with a TID value.
Request:
{
"id": "1",
"jsonrpc": "2.0",
"method": "get",
"params": [
{
"apiver": 3,
"url": "/report/adom/root/run/<tid>"
}
],
"session": "session-id"
}The report output can be retrieved via API if the output is eligible for text output; otherwise, generated reports can be sent to a pre-configured email addresses via Output Profile.
Request:
{
"id": "1",
"jsonrpc": "2.0",
"method": "get",
"params": [
{
"apiver": 3,
"data-type": "text",
"format": "CSV",
"url": "/report/adom/root/reports/data/tid"
}
],
"session": "session-id"
}
Troubleshooting:
Â
Run the following FortiManager CLI commands to debug the API calls:
Â
diagnose debug service httpd 255
diagnose debug service main 255