report.exportCsv
Run a net or category chart and return its data as CSV, as GnuCash's CSV export of those charts writes it.
Runs a net or category chart and returns its data as CSV, as GnuCash's CSV export of those charts writes it. Reports that
offer it have csv in their exportTypes (report.list): Net Worth Barchart and Linechart,
Income/Expense Chart and Linechart, Income Over Time, Expense Over Time, Assets Over Time and Liabilities Over Time.
The rows are the chart's data whatever its display options show.
Dates are ISO whatever the date format. Text is quoted, and numbers are written as Guile prints inexact numbers
(28.0, 1.0e-4), which is what GnuCash writes; red-ale computes them without floating point. Nothing is written to
disk; the CLI's --output writes the csv on your side. Any other report is refused with invalid
(no-export), and a chart with no figures with no-exportable-data.
Examples
Example: with a copy of the reports/category-daily example book open as book.gnucash, at 2024-03-15T12:00:00Z.
JSON-RPC
Request:
{"jsonrpc":"2.0","id":1,"method":"report.exportCsv","params":{"report":"Income Over Time","options":{"Accounts":{"Accounts":["a0000000000000000000000000000003"]},"General":{"Start Date":{"absolute":"2024-03-01"},"End Date":{"absolute":"2024-03-31"},"Step Size":"WeekDelta"}}}}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"title": "",
"csv": "\"Date\",\"account-3\"\n\"2024-03-01\",28.0\n\"2024-03-08\",77.0\n\"2024-03-15\",126.0\n\"2024-03-22\",175.0\n\"2024-03-29\",90.0"
}
}
Request:
{"jsonrpc":"2.0","id":2,"method":"report.exportCsv","params":{"report":"Balance Sheet"}}
Response:
{
"jsonrpc": "2.0",
"id": 2,
"error": {
"code": 2001,
"message": "…",
"data": {
"reason": "no-export",
"exportType": "csv",
"help": "error/invalid"
}
}
}
Command line
red-ale exec --book book.gnucash --script - <<'EOF'
report.exportCsv {"report":"Income Over Time","options":{"Accounts":{"Accounts":["a0000000000000000000000000000003"]},"General":{"Start Date":{"absolute":"2024-03-01"},"End Date":{"absolute":"2024-03-31"},"Step Size":"WeekDelta"}}}
report.exportCsv {"report":"Balance Sheet"}
EOF
It fails with exit status 2, printing on standard error:
{
"error": {
"code": 2001,
"message": "…",
"data": {
"reason": "no-export",
"exportType": "csv",
"help": "error/invalid"
}
}
}
MCP tool call
Tool call:
{"name":"report.exportCsv","arguments":{"report":"Income Over Time","options":{"Accounts":{"Accounts":["a0000000000000000000000000000003"]},"General":{"Start Date":{"absolute":"2024-03-01"},"End Date":{"absolute":"2024-03-31"},"Step Size":"WeekDelta"}}}}
Result:
{
"structuredContent": {
"title": "",
"csv": "\"Date\",\"account-3\"\n\"2024-03-01\",28.0\n\"2024-03-08\",77.0\n\"2024-03-15\",126.0\n\"2024-03-22\",175.0\n\"2024-03-29\",90.0"
}
}
Tool call:
{"name":"report.exportCsv","arguments":{"report":"Balance Sheet"}}
Result:
{
"isError": true,
"structuredContent": {
"error": {
"code": 2001,
"name": "invalid",
"message": "…",
"data": {
"reason": "no-export",
"exportType": "csv",
"help": "error/invalid"
}
}
}
}
Effect: read.
Params
Params of report.exportCsv.
report(ReportRef, required): The report: a net or category chart, or a saved configuration of one.options(ReportOptions or null): Changes over the template's defaults, or over the saved configuration's values.now(Timestamp or null): The time to run the report for; by default the session's clock.
Result
The result of report.exportCsv. Nothing is written to disk.
title(string, required): The report's title: empty for the charts, which GnuCash leaves untitled.csv(string, required): The CSV text, as GnuCash'sgnc:lists->csvwrites it: rows joined by\n, no newline after the last.