POST /v1/rules

Add a rule. A pattern that already has a rule is reported, not changed.

Auth. Send the token in the X-Ledger-Token header.

Request body

application/json: object

FieldTypeRequiredDescription
patternstringrequiredMatched against the normalized merchant text, case-insensitively
categorystringrequiredMust be on the category list
priorityintegeroptionalLower is tried first

Responses

StatusMeaningBody
201AddedRuleCreated
200The pattern already had a ruleRuleCreated
400Request rejectedError
429Too many requests from this client address. Wait the number of seconds in Retry-After, then try again.Error

Example response

{
  "id": 0,
  "pattern": "string",
  "category": "string",
  "created": true
}

Code samples

Set KEY to your own token first.

curl

curl \
  -X POST \
  -H X-Ledger-Token:$KEY \
  -H "Content-Type: application/json" \
  -d '{"pattern": "string", "category": "string", "priority": 1}' \
  "https://api.sasek.org/ledger/v1/rules"

JavaScript

const res = await fetch("https://api.sasek.org/ledger/v1/rules", {
  method: "POST",
  headers: { "X-Ledger-Token": KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    "pattern": "string",
    "category": "string",
    "priority": 1
  }),
});
const data = await res.json();

Python

import json
import os
import urllib.request

payload = {'pattern': 'string', 'category': 'string', 'priority': 1}

request = urllib.request.Request(
    "https://api.sasek.org/ledger/v1/rules",
    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))