Create a categorization rule
Changed onCreates a categorization rule in a Books instance: a rule that automatically categorizes imported transactions to a ledger, i.e. a general ledger (GL) account. The rule only applies to transactions categorized from now on; it does not re-categorize existing transactions. The body has conditions (1 to 10, all of which must match; logical AND, there is no OR) and outputs (at most one of each kind, so today exactly one setLedger), in the same shape getBooksCategorizationRules returns, so a listed rule's conditions and outputs can be sent back as is. Each condition has a tag and contents: amount (operator, one of lessThan, lessThanOrEqualTo, greaterThan, greaterThanOrEqualTo, or equalTo, and amount, a signed threshold in dollars: money in is positive and money out negative), description (contains), counterparty (name), debitCard (debitCardId), creditCard (creditCardId), user (userId), or customCategory (customCategoryId); every card, user, and custom category must belong to the organization. The only output is setLedger (ledgerId), a ledger the caller may edit (not read-only) in the Books instance; to find ledger IDs, use getBooksLedgers. There is no priority field: the new rule is placed among the existing rules by how specific its conditions are, and the first matching rule applies. Returns the created rule, in the shape getBooksCategorizationRules returns. A rule that doesn't validate, a ledger without a GL account, or conditions the organization already has a rule for are a 400 and create nothing; to see existing rules, use getBooksCategorizationRules.
Request
- Base URLhttps://api.mercury.com/api/v1
- AuthHTTP bearer
- TypeScriptA function with typed inputs. Its response is checked against the schema.
Query parameters
The Books instance to act on. Required for agent organization tokens; defaults to the token organization's instance.
Request body
Example request
{
"outputs": [
{
"contents": {
"ledgerId": "7JRNsKwy2Lw66caxVU7WGC"
}
}
]
}Response
Example response
{
"rule": {
"id": "00000000-0000-0000-0000-000000000000",
"lastApplied": "2016-07-22T00:00:00Z",
"outputs": [
{
"contents": {
"ledgerId": "7JRNsKwy2Lw66caxVU7WGC"
}
}
]
}
}Changes
- info
endpoint added
- info