{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/saturation-io/json-schema/saturation-io-transaction-schema.json",
  "title": "Transaction",
  "description": "A transaction in Saturation. Money uses minor currency units. A `CashAdvance` row is not spend, so leave it out of spend totals; `/transactions/stats` already does. The Cash Advance balance is not available through this API.",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/saturation-io-openapi.yml#/components/schemas/Transaction",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "source",
    "type",
    "status",
    "isReversal",
    "amount",
    "timestamp",
    "isItemized",
    "actualized",
    "projectId",
    "mergedFromIds",
    "createdAt",
    "updatedAt"
  ],
  "properties": {
    "id": {
      "allOf": [
        {
          "$ref": "#/$defs/Id"
        }
      ],
      "description": "Transaction ID."
    },
    "source": {
      "$ref": "#/$defs/TransactionSource"
    },
    "sourceId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Reference supplied by the transaction source."
    },
    "type": {
      "anyOf": [
        {
          "$ref": "#/$defs/TransactionType"
        },
        {
          "type": "null"
        }
      ]
    },
    "status": {
      "$ref": "#/$defs/TransactionStatus"
    },
    "isReversal": {
      "type": "boolean",
      "description": "Whether the transaction is a refund or another reversal."
    },
    "amount": {
      "$ref": "#/$defs/Money"
    },
    "exchangeRate": {
      "type": [
        "number",
        "null"
      ],
      "description": "Exchange rate to the workspace currency."
    },
    "exchangeRateSource": {
      "oneOf": [
        {
          "$ref": "#/$defs/ExchangeRateSource"
        },
        {
          "type": "null"
        }
      ]
    },
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "Time the transaction occurred."
    },
    "description": {
      "type": [
        "string",
        "null"
      ]
    },
    "merchant": {
      "type": [
        "string",
        "null"
      ],
      "description": "Merchant name supplied by the transaction source."
    },
    "logoUrl": {
      "type": [
        "string",
        "null"
      ],
      "format": "uri",
      "description": "Merchant logo URL."
    },
    "category": {
      "type": [
        "string",
        "null"
      ],
      "description": "Category supplied by the transaction source."
    },
    "sourceLast4": {
      "type": [
        "string",
        "null"
      ],
      "description": "Last four characters of the source account or card."
    },
    "sourceName": {
      "type": [
        "string",
        "null"
      ],
      "description": "Name of the source account or card."
    },
    "sourceOwner": {
      "type": [
        "string",
        "null"
      ],
      "description": "The cardholder on a shared card account, exactly as the bank reports it through Plaid (for example `AVERY HOLLIS 2041`). This is the label the app shows in the Source column. `sourceName` and `sourceLast4` still describe the parent account, so the digits here can differ from `sourceLast4`. Null for transactions that do not come from a `plaid` connection, when the bank reports no cardholder, and for some transactions imported before Saturation recorded cardholders."
    },
    "sourceDescription": {
      "type": [
        "string",
        "null"
      ],
      "readOnly": true,
      "description": "The text the bank feed reported for this transaction, as the app shows it under Source details (for example `Online ACH Payment Northwind Supply 0412`). Saturation's cleanup of `description` and `merchant`, and edits to them, never change it, so use it to identify the payee when the cleaned name is wrong. The bank feed may already have shortened it, and transactions imported at different times may carry more or less of the bank's text; it comes back exactly as Saturation received it, so do not parse it. Null when Saturation holds no bank text for the transaction, which today means every transaction that does not come from a `plaid` connection, and a bank transaction whose bank record was removed or cannot be told apart from another."
    },
    "number": {
      "type": [
        "string",
        "null"
      ],
      "description": "Document, check, or invoice number."
    },
    "ref": {
      "type": [
        "string",
        "null"
      ],
      "description": "External reference."
    },
    "payId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Related Saturation Pay payment ID."
    },
    "notes": {
      "type": [
        "string",
        "null"
      ],
      "description": "Notes about the transaction."
    },
    "contactId": {
      "anyOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ],
      "description": "Assigned contact ID."
    },
    "projectId": {
      "anyOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ],
      "description": "Assigned project ID, or `null` when unassigned."
    },
    "budgetLineId": {
      "anyOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ],
      "description": "Budget line ID. Itemized transactions store this on each item instead."
    },
    "fringeId": {
      "anyOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ]
    },
    "isItemized": {
      "type": "boolean",
      "description": "Whether the transaction has items."
    },
    "actualized": {
      "type": "boolean",
      "description": "Whether the transaction is included in budget actuals. A `CashAdvance` row never counts in actuals, whatever this flag says."
    },
    "purchaseOrderId": {
      "anyOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ],
      "description": "Linked purchase order ID."
    },
    "cashAdvanceId": {
      "anyOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ],
      "description": "The Cash Advance this row draws on. Null when there is no link, or when you cannot read the Cash Advance. Read-only; set it in Saturation."
    },
    "mergedFromIds": {
      "type": "array",
      "readOnly": true,
      "description": "IDs of the transactions merged into this one, empty when none. A read of one of these IDs returns this transaction. IDs only; read access to the merged transactions is not required to see them.",
      "items": {
        "$ref": "#/$defs/Id"
      }
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "contact": {
      "description": "Assigned contact. Included with `expand=contact`.",
      "oneOf": [
        {
          "$ref": "#/$defs/TransactionContactRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "documents": {
      "description": "Related documents. Included with `expand=documents`.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/TransactionDocumentRef"
      }
    },
    "items": {
      "type": "array",
      "description": "Transaction items. Included with `expand=items`.",
      "items": {
        "$ref": "#/$defs/TransactionItem"
      }
    },
    "account": {
      "description": "Budget account. Included with `expand=account`.",
      "oneOf": [
        {
          "$ref": "#/$defs/TransactionAccountRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "purchaseOrder": {
      "description": "Linked purchase order. Included with `expand=purchaseOrder`.",
      "oneOf": [
        {
          "$ref": "#/$defs/TransactionPurchaseOrderRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "suggestions": {
      "$ref": "#/$defs/TransactionSuggestions"
    }
  },
  "$defs": {
    "ExchangeRateSource": {
      "type": "string",
      "description": "Source of the exchange rate. The API may return values not listed below.",
      "x-extensible-enum": true,
      "enum": [
        "bank",
        "api",
        "user"
      ]
    },
    "Id": {
      "type": "string",
      "description": "A stable resource ID, such as `prj_…`, `txn_…`, or `doc_…`."
    },
    "Money": {
      "type": "object",
      "description": "An amount in integer minor units and its ISO-4217 currency.",
      "required": [
        "amount",
        "currency"
      ],
      "additionalProperties": false,
      "properties": {
        "amount": {
          "type": "integer",
          "format": "int64",
          "minimum": -4503599627370496,
          "maximum": 4503599627370496,
          "description": "Amount in the currency's smallest unit, such as cents. May be negative, and at most 2^52 either way."
        },
        "currency": {
          "type": "string",
          "description": "ISO-4217 currency code.",
          "minLength": 3,
          "maxLength": 3,
          "pattern": "^[A-Za-z]{3}$"
        }
      }
    },
    "TransactionAccountRef": {
      "type": "object",
      "description": "Budget account included through `expand=account` or `expand=items.account`.",
      "additionalProperties": false,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": "string"
        },
        "code": {
          "type": [
            "string",
            "null"
          ],
          "description": "Account code."
        }
      }
    },
    "TransactionContactRef": {
      "type": "object",
      "description": "Contact details included with a transaction.",
      "required": [
        "id",
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "TransactionDocumentRef": {
      "type": "object",
      "description": "Document details included with a transaction.",
      "required": [
        "id",
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "TransactionItem": {
      "type": "object",
      "description": "An item in an itemized transaction. Budget coding belongs to each item instead of the transaction.",
      "additionalProperties": false,
      "required": [
        "id",
        "lineNumber",
        "amount",
        "tagIds",
        "tags"
      ],
      "properties": {
        "id": {
          "allOf": [
            {
              "$ref": "#/$defs/Id"
            }
          ],
          "description": "Transaction item ID."
        },
        "lineNumber": {
          "type": [
            "string",
            "null"
          ],
          "description": "Line number shown in the itemization."
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "description": "Item description."
        },
        "budgetLineId": {
          "anyOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ],
          "description": "Budget line ID."
        },
        "fringeId": {
          "anyOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ],
          "description": "Applied fringe ID."
        },
        "contactId": {
          "anyOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ],
          "description": "Contact for this item."
        },
        "qty": {
          "type": [
            "string",
            "null"
          ],
          "description": "Quantity or formula."
        },
        "unit": {
          "type": [
            "string",
            "null"
          ],
          "description": "Unit, such as `Day`, `Hour`, or `Flat`."
        },
        "customUnitId": {
          "anyOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ],
          "description": "Custom unit ID."
        },
        "rate": {
          "type": [
            "string",
            "null"
          ],
          "description": "Rate or formula."
        },
        "amount": {
          "oneOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ]
        },
        "overtime": {
          "type": [
            "string",
            "null"
          ],
          "description": "Overtime amount or formula."
        },
        "taxable": {
          "type": [
            "string",
            "null"
          ],
          "description": "Taxable amount or formula."
        },
        "nonTaxable": {
          "type": [
            "string",
            "null"
          ],
          "description": "Non-taxable amount or formula."
        },
        "account": {
          "description": "Budget account for the item. Included with `expand=items.account`.",
          "oneOf": [
            {
              "$ref": "#/$defs/TransactionAccountRef"
            },
            {
              "type": "null"
            }
          ]
        },
        "tagIds": {
          "type": "array",
          "description": "Tag IDs assigned to this item.",
          "items": {
            "$ref": "#/$defs/Id"
          }
        },
        "tags": {
          "type": "array",
          "description": "Tags assigned to this item.",
          "items": {
            "$ref": "#/$defs/TransactionItemTag"
          }
        },
        "cashAdvanceId": {
          "anyOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ],
          "description": "The Cash Advance this line pays back to its holder. Null when there is no link, or when you cannot read the Cash Advance. Read-only; set it in Saturation."
        }
      }
    },
    "TransactionItemTag": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "color"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": "string"
        },
        "color": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "TransactionPurchaseOrderRef": {
      "type": "object",
      "description": "Purchase order details included with a transaction.",
      "required": [
        "id",
        "number"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "number": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "TransactionSource": {
      "type": "string",
      "description": "How the transaction entered Saturation. `document` rows were imported from a file, `receipt` rows were created from a scanned receipt or invoice, and `saturation_billing` rows are charges Saturation billed to the workspace. Financial fields are editable only for `manual` transactions. New values may be added; treat an unknown value as read-only.",
      "enum": [
        "manual",
        "plaid",
        "saturation_pay",
        "saturation_credit",
        "document",
        "receipt",
        "saturation_billing"
      ]
    },
    "TransactionStatus": {
      "type": "string",
      "description": "Current transaction status. Available statuses vary by source.",
      "enum": [
        "unpaid",
        "pending",
        "posted",
        "void",
        "needs_review",
        "projected",
        "rejected"
      ]
    },
    "TransactionSuggestedAccount": {
      "type": "object",
      "description": "The suggested account (budget line).",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "code",
        "reason",
        "message"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "code": {
          "type": [
            "string",
            "null"
          ]
        },
        "reason": {
          "$ref": "#/$defs/TransactionSuggestionReason"
        },
        "message": {
          "type": "string",
          "description": "Why it was suggested, as the app shows it."
        }
      }
    },
    "TransactionSuggestedContact": {
      "description": "The suggested contact, or a new one to create by `name`.",
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "id",
            "name",
            "reason",
            "message"
          ],
          "properties": {
            "id": {
              "$ref": "#/$defs/Id"
            },
            "name": {
              "type": "string"
            },
            "reason": {
              "$ref": "#/$defs/TransactionSuggestionReason"
            },
            "message": {
              "type": "string",
              "description": "Why it was suggested, as the app shows it."
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "isNew",
            "name",
            "reason",
            "message"
          ],
          "properties": {
            "isNew": {
              "type": "boolean",
              "const": true
            },
            "name": {
              "type": "string"
            },
            "reason": {
              "$ref": "#/$defs/TransactionSuggestionReason"
            },
            "message": {
              "type": "string",
              "description": "Why it was suggested, as the app shows it."
            }
          }
        }
      ]
    },
    "TransactionSuggestedProject": {
      "type": "object",
      "description": "The suggested project.",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "isViewable",
        "reason",
        "message"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": "string"
        },
        "isViewable": {
          "type": "boolean",
          "description": "False for a project you may code transactions into but not open."
        },
        "reason": {
          "$ref": "#/$defs/TransactionSuggestionReason"
        },
        "message": {
          "type": "string",
          "description": "Why it was suggested, as the app shows it."
        }
      }
    },
    "TransactionSuggestedUpdate": {
      "type": "object",
      "description": "One item for `PATCH /transactions/bulk`, ready to post as it is. It holds only what you can write: there is none for a workspace API key or a service token, which can't bulk update, nor on a transaction you can't update or that is locked, and it leaves out a project you can't move it into (with the account that would set it) and a locked field. `ifMatch` holds each changed field's current value, so a transaction coded since this read fails `precondition_failed`.",
      "additionalProperties": false,
      "required": [
        "id",
        "changes",
        "ifMatch",
        "suggestionToken"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "changes": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "projectId": {
              "$ref": "#/$defs/Id"
            },
            "budgetLineId": {
              "$ref": "#/$defs/Id"
            },
            "contactId": {
              "$ref": "#/$defs/Id"
            },
            "contactName": {
              "type": "string"
            }
          }
        },
        "ifMatch": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "projectId": {
              "anyOf": [
                {
                  "$ref": "#/$defs/Id"
                },
                {
                  "type": "null"
                }
              ]
            },
            "budgetLineId": {
              "anyOf": [
                {
                  "$ref": "#/$defs/Id"
                },
                {
                  "type": "null"
                }
              ]
            },
            "contactId": {
              "anyOf": [
                {
                  "$ref": "#/$defs/Id"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "suggestionToken": {
          "type": "string"
        }
      }
    },
    "TransactionSuggestionReason": {
      "type": "string",
      "description": "`rule`: a deterministic engine rule. `history`: a learned option past this workspace's threshold for the field. `merchant_name`: a contact named like the merchant.",
      "enum": [
        "rule",
        "history",
        "merchant_name"
      ]
    },
    "TransactionSuggestions": {
      "type": "object",
      "description": "What to do next with a transaction's coding, and the coding engine's suggestions for it. Included with `expand=suggestions` on every transaction; one older than 90 days reads `ineligible`. `ready`: post `bulkUpdateItem` to `PATCH /transactions/bulk`. The item may be partial or absent, since it holds only what you can write; when there is none and you can update the transaction, code it yourself. `already_coded`: nothing to do; an itemized transaction reads this way, since its accounts are on its items. `queued`: the engine scores it soon (`queuedAt`); read again later, not in a loop. `off` and `ineligible` (with `reason`): no suggestion will come, so code it yourself. A suggestion never names a project, account or contact you can't read.",
      "additionalProperties": false,
      "required": [
        "status"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "ready",
            "already_coded",
            "queued",
            false,
            "ineligible"
          ]
        },
        "reason": {
          "type": "string",
          "description": "Why `off` (`paused`, `not_enabled`) or `ineligible`. `demo`: a demo project's sample transaction. `removed_twin`: a bank transaction with a twin the bank removed, still live and holding the coding.",
          "enum": [
            "paused",
            "not_enabled",
            "not_a_charge",
            "transfer",
            "refund",
            "not_posted",
            "older_than_90_days",
            "removed_by_bank",
            "demo",
            "removed_twin"
          ]
        },
        "queuedAt": {
          "type": "string",
          "format": "date-time",
          "description": "When a `queued` transaction last changed."
        },
        "project": {
          "$ref": "#/$defs/TransactionSuggestedProject"
        },
        "account": {
          "$ref": "#/$defs/TransactionSuggestedAccount"
        },
        "contact": {
          "$ref": "#/$defs/TransactionSuggestedContact"
        },
        "bulkUpdateItem": {
          "$ref": "#/$defs/TransactionSuggestedUpdate"
        }
      }
    },
    "TransactionType": {
      "type": "string",
      "description": "Transaction type. The API may return values not listed below. `CashAdvance`: Cash handed to a person, not spend. With `cashAdvanceId` null it is the Cash Advance itself, or a cash move for one you cannot read. With `cashAdvanceId` set it moves cash for that Cash Advance: a negative amount is cash returned, a positive amount is cash paid to the holder. Other types with `cashAdvanceId` set are spend.",
      "x-extensible-enum": true,
      "enum": [
        "SaturationPCard",
        "ACH",
        "Cash",
        "CashAdvance",
        "Check",
        "CreditCard",
        "Deposit",
        "ETransfer",
        "Invoice",
        "Projection",
        "TimeCard",
        "Wire",
        "Withdrawal"
      ]
    }
  }
}