POST /v1/transactions/{id}/split
Split a transaction into parts that add up to its amount
The parent is kept as history but no longer counted in totals; each part is counted instead, and carries its own category. Parts must have the same sign as the transaction.
Auth. Send the token in the X-Ledger-Token header.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
id | path | integer | required |
Request body
application/json: object
| Field | Type | Required | Description |
|---|---|---|---|
parts | object[] | required |
Responses
| Status | Meaning | Body |
|---|---|---|
201 | Split. The parent id and the parts. | object |
400 | Request rejected | Error |
404 | Request rejected | Error |
409 | 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
{
"parent": 0,
"parts": [
{
"id": 0,
"amount_cents": 0,
"category": "string",
"note": "string"
}
]
}
Code samples
Set KEY to your own token first.
curl
curl \
-X POST \
-H X-Ledger-Token:$KEY \
-H "Content-Type: application/json" \
-d '{"parts": [{"amount_cents": 0, "category": "string", "note": "string"}]}' \
"https://api.sasek.org/ledger/v1/transactions/{id}/split"
JavaScript
const res = await fetch("https://api.sasek.org/ledger/v1/transactions/{id}/split", {
method: "POST",
headers: { "X-Ledger-Token": KEY, "Content-Type": "application/json" },
body: JSON.stringify({
"parts": [
{
"amount_cents": 0,
"category": "string",
"note": "string"
}
]
}),
});
const data = await res.json();
Python
import json
import os
import urllib.request
payload = {'parts': [{'amount_cents': 0, 'category': 'string', 'note': 'string'}]}
request = urllib.request.Request(
"https://api.sasek.org/ledger/v1/transactions/{id}/split",
method="POST",
headers={
"X-Ledger-Token": os.environ["KEY"],
"Content-Type": "application/json",
},
data=json.dumps(payload).encode(),
)
with urllib.request.urlopen(request) as response:
print(json.load(response))