You can provide up to 10 tags on Ledger Entries to store arbitrary key-value pairs, like IDs from your product.
You can define tags on Ledger Entry types in your Schema:
{
"key": "...",
"chartOfAccounts": {...},
"ledgerEntries": {
"types": [
{
"type": "user_funds_account",
"description": "Fund {{user_id}}",
"lines": [
{
"key": "increase_user_balance",
"account": {
"path": "liabilities/users:{{user_id}}/available"
},
"amount": "{{funding_amount}}"
},
{...other line}
],
"tags": [
{
"key": "user",
"value": "{{user_id}}"
},
{
"key": "deposit_flow",
"value": "{{deposit_flow_id}}"
},
{
"key": "deposit_flow_type",
"value": "ach"
}
]
}
]
}
}You can use the same parameter for both tag values and account paths.
When posting a Ledger Entry, include tag values as parameters:
mutation AddLedgerEntry(
$ik: SafeString!
$entry: LedgerEntryInput!
) {
addLedgerEntry(
ik: $ik,
entry: $entry
) {
__typename
... on AddLedgerEntryResult {
entry {
type
ik
tags {
key
value
}
}
lines {
amount
description
account {
path
}
}
}
... on Error {
code
message
}
}
}{
"ik": "fund-abc",
"entry": {
"ledger": {
"ik": "quickstart-ledger"
},
"type": "user_funds_account",
"parameters": {
"user_id": "user-1",
"funding_amount": "200",
"deposit_flow_id": "deposit-123"
}
}
}The Ledger Entry will have the tags you defined in the Schema:
{
"data": {
"addLedgerEntry": {
"entry": {
"type": "user_funds_account",
"ik": "fund-abc",
"tags": [
{
"key": "user",
"value": "user-1"
},
{
"key": "deposit_flow",
"value": "deposit-123"
},
{
"key": "deposit_flow_type",
"value": "ach"
}
]
},
"lines": [...]
}
}
}You can define tags at runtime when posting a Ledger Entry:
{
"ik": "add-ledger-entry",
"entry": {
"ledger": {
"ik": "quickstart-ledger"
},
"type": "user_funds_account",
"parameters": {
"user_id": "testing-user",
"funding_amount": "200",
"deposit_flow_id": "abc"
},
"tags": [
{
"key": "deposit_flow_type",
"value": "ach"
},
{
"key": "operator",
"value": "alice"
}
]
}
}If you define tags both at runtime and in the Schema, the Ledger Entry will get the combined set of tags:
{
"data": {
"addLedgerEntry": {
"entry": {
"type": "user_funds_account",
"ik": "fund-abc",
"tags": [
{
"key": "user",
"value": "user-1"
},
{
"key": "deposit_flow",
"value": "deposit-123"
},
{
"key": "deposit_flow_type",
"value": "ach"
},
{
"key": "operator",
"value": "alice"
}
]
},
"lines": [...]
}
}
}You can specify the same tag key in both places only if they have the same value.
In addition to tags defined in your Schema, you can add and update tags on a posted Ledger Entry.
mutation UpdateLedgerEntryTags(
$ledgerEntry: LedgerEntryMatchInput!
$update: UpdateLedgerEntryInput!
) {
updateLedgerEntry(
ledgerEntry: $ledgerEntry,
update: $update
) {
__typename
... on UpdateLedgerEntryResult {
entry {
type
ik
tags {
key
value
}
lines {
nodes {
amount
description
account {
path
}
}
}
}
}
... on Error {
code
message
}
}
}{
"ledgerEntry": {
"ik": "add-ledger-entry",
"ledger": {
"ik": "quickstart-ledger"
}
},
"update": {
"tags": [
{
"key": "operator",
"value": "bob"
},
{
"key": "supervisor",
"value": "eve"
}
]
}
}This is an additive operation:
You can only update a Ledger Entry a maximum of 10 times.