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

NameInTypeRequiredDescription
idpathintegerrequired

Request body

application/json: object

FieldTypeRequiredDescription
partsobject[]required

Responses

StatusMeaningBody
201Split. The parent id and the parts.object
400Request rejectedError
404Request rejectedError
409Request rejectedError
429Too 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))