export.csvTransactions
Transactions of some accounts and dates as CSV text, in GnuCash's simple or complex layout. Writes no file.
Returns the transactions of some accounts, between two dates, as CSV text in GnuCash's Export Transactions to CSV
layout. It writes no file. layout: complex (the default) writes one line per split with the transaction's ID;
simple writes one line per transaction, for its split in the exported account. A transaction is written once, under
the first account in accounts it has a split in, so the order of accounts matters.
Dates and numbers follow the Locale (the locale setting, or locale for this call), so the default C locale gives
06/03/24 and $3.50. In the simple layout the header says Account Name but the column holds the full name, as in
GnuCash.
Examples
Example: with a new, empty book open as book.gnucash.
JSON-RPC
Request:
{"jsonrpc":"2.0","id":1,"method":"account.create","params":{"name":"Checking","type":"BANK","commodity":"USD"}}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": "…"
}
Request:
{"jsonrpc":"2.0","id":2,"method":"account.create","params":{"name":"Food","type":"EXPENSE","commodity":"USD"}}
Response:
{
"jsonrpc": "2.0",
"id": 2,
"result": "…"
}
Request:
{"jsonrpc":"2.0","id":3,"method":"transaction.post","params":{"datePosted":"2024-06-03","description":"Coffee","splits":[{"account":"Food","value":"3.50"},{"account":"Checking","value":"-3.50"}]}}
Response:
{
"jsonrpc": "2.0",
"id": 3,
"result": "…"
}
Request:
{"jsonrpc":"2.0","id":4,"method":"export.csvTransactions","params":{"accounts":["Checking"],"layout":"simple"}}
Response:
{
"jsonrpc": "2.0",
"id": 4,
"result": {
"csv": "Date,Account Name,Number,Description,Full Category Path,Reconcile,Amount With Sym,Amount Num.,Value With Sym,Value Num.,Rate/Price\r\n06/03/24,Checking,,Coffee,Food,n,-$3.50,-3.50,-$3.50,-3.50,1.00\r\n",
"transactions": 1,
"lines": 1
}
}
Request:
{"jsonrpc":"2.0","id":5,"method":"export.csvTransactions","params":{"accounts":["Checking"],"from":"2024-07-01"}}
Response:
{
"jsonrpc": "2.0",
"id": 5,
"result": {
"transactions": 0,
"lines": 0,
"…": "…"
}
}
Command line
red-ale exec --book book.gnucash --script - <<'EOF'
account.create {"name":"Checking","type":"BANK","commodity":"USD"}
account.create {"name":"Food","type":"EXPENSE","commodity":"USD"}
transaction.post {"datePosted":"2024-06-03","description":"Coffee","splits":[{"account":"Food","value":"3.50"},{"account":"Checking","value":"-3.50"}]}
export.csvTransactions {"accounts":["Checking"],"layout":"simple"}
export.csvTransactions {"accounts":["Checking"],"from":"2024-07-01"}
EOF
It prints:
[
"…",
"…",
"…",
{
"csv": "Date,Account Name,Number,Description,Full Category Path,Reconcile,Amount With Sym,Amount Num.,Value With Sym,Value Num.,Rate/Price\r\n06/03/24,Checking,,Coffee,Food,n,-$3.50,-3.50,-$3.50,-3.50,1.00\r\n",
"transactions": 1,
"lines": 1
},
{
"transactions": 0,
"lines": 0,
"…": "…"
}
]
MCP tool call
Tool call:
{"name":"account.create","arguments":{"name":"Checking","type":"BANK","commodity":"USD"}}
Result:
{
"content": [
{
"type": "text",
"text": "\"…\""
}
]
}
Tool call:
{"name":"account.create","arguments":{"name":"Food","type":"EXPENSE","commodity":"USD"}}
Result:
{
"content": [
{
"type": "text",
"text": "\"…\""
}
]
}
Tool call:
{"name":"transaction.post","arguments":{"datePosted":"2024-06-03","description":"Coffee","splits":[{"account":"Food","value":"3.50"},{"account":"Checking","value":"-3.50"}]}}
Result:
{
"content": [
{
"type": "text",
"text": "\"…\""
}
]
}
Tool call:
{"name":"export.csvTransactions","arguments":{"accounts":["Checking"],"layout":"simple"}}
Result:
{
"structuredContent": {
"csv": "Date,Account Name,Number,Description,Full Category Path,Reconcile,Amount With Sym,Amount Num.,Value With Sym,Value Num.,Rate/Price\r\n06/03/24,Checking,,Coffee,Food,n,-$3.50,-3.50,-$3.50,-3.50,1.00\r\n",
"transactions": 1,
"lines": 1
}
}
Tool call:
{"name":"export.csvTransactions","arguments":{"accounts":["Checking"],"from":"2024-07-01"}}
Result:
{
"structuredContent": {
"transactions": 0,
"lines": 0,
"…": "…"
}
}
Effect: read.
Params
Params of export.csvTransactions.
accounts(array of AccountRef, required): The accounts, at least one, in the order to process them; a transaction goes under the first one it has a split in. Sub-accounts are not included unless listed.from(Date or null): Posted on or after local 00:00:00 of this date; by default the earliest.to(Date or null): Posted on or before local 23:59:59 of this date; by default the latest.layout(LayoutParam):simpleorcomplex(the default).separator(string): The field separator: any non-empty string.quotes(boolean): Quote every field.locale(string or null): The Locale to format numbers and dates in: a supported POSIX locale name (fr_FR,C) orenvironment; by default the Configuration'slocalesetting.
Result
The result of export.csvTransactions.
csv(string, required): The CSV text: UTF-8, every line ending in CRLF, the header first.transactions(integer (uint), required): Transactions written.lines(integer (uint), required): Lines written, the header not counted.