Export data
Get transactions out as CSV, in GnuCash's simple or complex layout, and the account tree as CSV or as a file of accounts and commodities.
To use your data in a spreadsheet, send it to an accountant, or load it into another book, export it. red-ale has three exports. None changes the book.
| Export | Gives | Format |
|---|---|---|
| export.csvTransactions | Transactions of chosen accounts and dates | CSV text in the result |
| export.csvTree | The account tree: type, name, code, commodity, flags | CSV text in the result |
| export.accounts | The accounts and their commodities, to be imported as a new book's chart | A file of a book with no transactions |
Steps
- Transactions. Call export.csvTransactions with the
accountsto export (a transaction appears under the first of them it has a split in), optionallyfromandto, and alayout:simple, one line per split with the other account in the line, orcomplex(the default), GnuCash's full layout with one line per split and its memo, action and price.separatorandquotesshape the CSV;localedecides how dates and numbers are written. The CSV is in the result ascsv. From the command line,--output transactions.csvwrites it to a file. - The account tree. export.csvTree gives one row per account in the layout that Import transactions and GnuCash's account import read.
- A chart of accounts. export.accounts writes the accounts and commodities, without the
transactions, to a new book at
path. It refuses a path that exists. Use it to start a new year's book with the same chart. - A report's figures. Reports with a CSV export give theirs through report.exportCsv (see Run and export a report).
Example
Example: with a new, empty book open as book.gnucash, at 2024-07-01T12:00:00Z.
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.csvTree","params":{}}
Response:
{
"jsonrpc": "2.0",
"id": 5,
"result": {
"csv": "Type,Full Account Name,Account Name,Account Code,Description,Account Color,Notes,Symbol,Namespace,Hidden,Tax Info,Placeholder\r\nEXPENSE,Food,Food,,,,,USD,CURRENCY,F,F,F\r\nBANK,Checking,Checking,,,,,USD,CURRENCY,F,F,F\r\n",
"rows": 2
}
}
Request:
{"jsonrpc":"2.0","id":6,"method":"export.accounts","params":{"path":"chart"}}
Response:
{
"jsonrpc": "2.0",
"id": 6,
"result": {
"path": "…",
"accounts": 3,
"commodities": "…"
}
}
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.csvTree {}
export.accounts {"path":"chart"}
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
},
{
"csv": "Type,Full Account Name,Account Name,Account Code,Description,Account Color,Notes,Symbol,Namespace,Hidden,Tax Info,Placeholder\r\nEXPENSE,Food,Food,,,,,USD,CURRENCY,F,F,F\r\nBANK,Checking,Checking,,,,,USD,CURRENCY,F,F,F\r\n",
"rows": 2
},
{
"path": "…",
"accounts": 3,
"commodities": "…"
}
]
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.csvTree","arguments":{}}
Result:
{
"structuredContent": {
"csv": "Type,Full Account Name,Account Name,Account Code,Description,Account Color,Notes,Symbol,Namespace,Hidden,Tax Info,Placeholder\r\nEXPENSE,Food,Food,,,,,USD,CURRENCY,F,F,F\r\nBANK,Checking,Checking,,,,,USD,CURRENCY,F,F,F\r\n",
"rows": 2
}
}
Tool call:
{"name":"export.accounts","arguments":{"path":"chart"}}
Result:
{
"structuredContent": {
"path": "…",
"accounts": 3,
"commodities": "…"
}
}