export.accounts
Write a new book file holding the open book's account tree and commodities, and no transactions. Never overwrites a file.
Writes a new book file with the open book's account tree and commodities and no transactions: a chart of
accounts to start another book from. It never overwrites a file: a path that exists
is refused with file-exists. .gnucash is added when missing. The open book is not changed.
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":"export.accounts","params":{"path":"chart"}}
Response:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"path": "…",
"accounts": 2,
"commodities": 2
}
}
Request:
{"jsonrpc":"2.0","id":3,"method":"export.accounts","params":{"path":"chart"}}
Response:
{
"jsonrpc": "2.0",
"id": 3,
"error": {
"code": 1007,
"message": "…",
"data": {
"path": "…",
"help": "error/file-exists"
}
}
}
Command line
red-ale exec --book book.gnucash --script - <<'EOF'
account.create {"name":"Checking","type":"BANK","commodity":"USD"}
export.accounts {"path":"chart"}
export.accounts {"path":"chart"}
EOF
It fails with exit status 2, printing on standard error:
{
"error": {
"code": 1007,
"message": "…",
"data": {
"path": "…",
"help": "error/file-exists"
}
}
}
MCP tool call
Tool call:
{"name":"account.create","arguments":{"name":"Checking","type":"BANK","commodity":"USD"}}
Result:
{
"content": [
{
"type": "text",
"text": "\"…\""
}
]
}
Tool call:
{"name":"export.accounts","arguments":{"path":"chart"}}
Result:
{
"structuredContent": {
"path": "…",
"accounts": 2,
"commodities": 2
}
}
Tool call:
{"name":"export.accounts","arguments":{"path":"chart"}}
Result:
{
"isError": true,
"structuredContent": {
"error": {
"code": 1007,
"name": "file-exists",
"message": "…",
"data": {
"path": "…",
"help": "error/file-exists"
}
}
}
}
Effect: read.
Params
Params of export.accounts.
path(string, required): The new book file: a path orxml://URI that does not exist..gnucashis added when missing.
Result
The result of export.accounts.
path(string, required): The file written, uncompressed.accounts(integer (uint), required): Account elements written, the root account's included.commodities(integer (uint), required): Commodity elements written.