POST /v1/imports
Import a Ledger CSV v1 file for one account. Format in docs/import-format.md.
The whole file is validated before anything is written; any invalid row rejects the file. Duplicates (same account, date and amount) are skipped. Send the file as the request body with Content-Type text/csv, up to 1 MB.
Auth. Send the token in the X-Ledger-Token header.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
account_id | query | string | required | |
dry_run | query | boolean | optional | When true, classify and count without writing |
filename | query | string | optional | |
Idempotency-Key | header | string | optional | Send a unique key per logical import. A retry with the same key returns the first response. Keys are kept for a day. |
Request body
text/csv: string
Responses
| Status | Meaning | Body |
|---|---|---|
201 | Imported | ImportResult |
200 | Dry run; nothing was written | ImportResult |
400 | The file was rejected. Nothing was imported. Every bad row is listed. | object |
415 | Request rejected | Error |
429 | Too many requests from this client address. Wait the number of seconds in Retry-After, then try again. | Error |
Example response
{
"dry_run": true,
"import_id": 0,
"rows_total": 0,
"rows_new": 0,
"rows_duplicate": 0,
"uncategorized": 0,
"categorized_by_you": 0,
"categorized_by_rule": 0
}
Code samples
Set KEY to your own token first.
curl
curl \
-X POST \
-H X-Ledger-Token:$KEY \
-H "Content-Type: text/csv" --data-binary @file \
"https://api.sasek.org/ledger/v1/imports?account_id=string"
JavaScript
const res = await fetch("https://api.sasek.org/ledger/v1/imports?account_id=string", {
method: "POST",
headers: { "X-Ledger-Token": KEY },
});
const data = await res.json();
Python
import json
import os
import urllib.request
request = urllib.request.Request(
"https://api.sasek.org/ledger/v1/imports?account_id=string",
method="POST",
headers={
"X-Ledger-Token": os.environ["KEY"],
"Content-Type": "text/csv",
},
data=open("file.csv", "rb").read(),
)
with urllib.request.urlopen(request) as response:
print(json.load(response))