# Money in the API

> The JSON format of money and decimal values, input rules and errors, totals per currency, exchange rates and conversion over the API, MCP and the CLI, and the CSV format.

Source: https://docs.ligament.ai/developers/money/

This page covers the wire format. For what the field types do, see the guide [Money and currencies](https://docs.ligament.ai/guides/building-apps/money/index.md).

## Values

| Field type | JSON value | Example |
| --- | --- | --- |
| `money` | An object with the amount as a **string** | `{ "amount": "1234.50", "currency": "USD" }` |
| `decimal` | A string | `"0.125"` |
| `number`, `currency` (older types) | A JSON number | `1234.5` |

Amounts are strings because a JSON number is read as a floating-point number by most clients, and that can’t hold every decimal exactly. Parse them with a decimal library, such as `decimal.js` in JavaScript, `decimal.Decimal` in Python or `BigDecimal` in Java. Don’t use `parseFloat`.

The amount always has the field’s places: `"12.50"`, not `"12.5"`. Its `currency` is the field’s fixed currency, or the record’s currency field. It’s `null` if the record has none yet.

A masked amount is masked whole, so you get `"•••••"` instead of the object. A hidden field is absent. See [field levels](https://docs.ligament.ai/guides/access/index.md).

```json
GET /api/records/opportunity?limit=1
{
  "rows": [
    { "id": "cmx3…", "name": "Brightwater API rollout", "amount": { "amount": "12000.00", "currency": "USD" }, "probability": 10 }
  ]
}
```

## Writing amounts

You can send a money value in three forms:

-   `{ "amount": "1234.50", "currency": "USD" }`;
-   a decimal string, `"1234.50"`, which takes the field’s or the record’s currency;
-   a JSON number, `1234.5`, only if it’s exactly what you meant (at most 15 significant digits).

Values are **never rounded** on the way in. Every write below is refused with status 422 and nothing is saved:

| You send | Error |
| --- | --- |
| `"amount": "12.345"` to a USD field | `Amount (ARR): USD amounts have at most 2 decimal places (got "12.345")` |
| `"amount": { "amount": "12.50", "currency": "EUR" }` to a USD field | `Amount (ARR) is in USD; got EUR (convert it first)` |
| `"amount": "1,250.00"` | `Amount (ARR): "1,250.00" is not a decimal number (digits with an optional "." and sign, e.g. "1234.50")` |
| `"amount": 0.30000000000000004` | `Amount (ARR): 0.30000000000000004 has more digits than a JSON number holds exactly; send it as a string` |

On a record with a currency field, an amount in another currency is refused, and an amount sent while the currency field is empty fills it in. Changing the record’s currency re-checks its stored amounts. For example, moving `12.50` from USD to JPY is refused unless you send a new amount too.

## Totals

`GET /api/records/<entity>?summary=1` (or with `groupBy`) adds a `summary`. Money and decimal fields are under `totals`, computed exactly in SQL `numeric`. Money is never added across currencies. For example:

```json
"summary": {
  "total": 82,
  "sums": { "probability": 4725 },
  "totals": {
    "amount": { "kind": "money", "byCurrency": [{ "currency": "USD", "amount": "2284176.00" }] },
    "salary": { "kind": "money", "byCurrency": [{ "currency": "EUR", "amount": "612000.00" }, { "currency": "THB", "amount": "2040000.00" }] },
    "quantity": { "kind": "decimal", "amount": "1250.500" }
  },
  "groups": null
}
```

With `groupBy`, each group has its own `totals`. `sums` keeps the older `number` and `currency` fields as JSON numbers, as before. A field you can’t read in clear on every row has no total. With per-record field rules the check is on the rows being added up: a total (or a group’s) is present when every one of its rows is in clear for the caller, and absent when any is masked or hidden. Filters and sorts on such a field still match nothing.

Reports and dashboard queries (`POST /api/reports/run`) work the same way. A money metric in one currency returns `amount` and `currency`. A metric spanning several currencies returns `byCurrency` and no single `value`. Grouped buckets carry their `currency`. `value` is only there to draw charts, so show `amount`.

## Exchange rates

| Call | Who | What it does |
| --- | --- | --- |
| `GET /api/fx/rates?asOf=2026-11-15` | Anyone who can read records (`records:read`) | The rates in force on that date (default today) |
| `POST /api/fx/rates` | Admins and owners (`settings:write`) | Set a rate from a date: `{ "base": "EUR", "quote": "USD", "rate": "1.0845", "from": "2026-11-01" }` |
| `POST /api/fx/convert` | Anyone who can read rates (`records:read`) | Convert an amount (below) |
| `POST /api/fx/sync` | Admins and owners (`settings:write`) | Pull the day’s rates from the enabled rate source |

`asOf` takes a date `YYYY-MM-DD` in the workspace’s time zone, or `@today`, `@end_of_last_month`, `@end_of_last_quarter` or `@end_of_last_year`. A rate has at most 10 decimal places.

```json
POST /api/fx/convert
{ "amount": { "amount": "1250.00", "currency": "EUR" }, "to": "USD", "asOf": "2026-11-15" }

200
{ "amount": "1355.62", "currency": "USD", "from": { "amount": "1250.00", "currency": "EUR" },
  "rate": "1.0845", "rateDate": "2026-11-01", "source": "manual" }
```

`rateDate` is the date the rate took effect. If only the opposite pair exists, the answer uses its inverse and adds `"inverse": true`, with a source such as `"manual (inverse)"`. The amount is rounded half-even to the target currency’s places.

| Code | When |
| --- | --- |
| `fx_rate_missing` (422) | No rate for the pair on that date: `No exchange rate from EUR to USD on 2026-10-01` |
| `fx_invalid` (422) | A malformed body |
| Other 422 codes, such as `invalid_currency` or `invalid_decimal` | A bad currency code or amount; the message names the value |
| `fx_source_missing` | A sync with no enabled rate source |
| `fx_source_failed`, `fx_source_invalid` | The rate source didn’t answer, or answered with something unusable |

**MCP:** `fx_convert` and `fx_rates`, with the same arguments and answers, need `records:read`. See [MCP](https://docs.ligament.ai/developers/mcp/index.md).

**CLI:** see [CLI](https://docs.ligament.ai/developers/cli/index.md).

```sh
ligament fx rates --as-of 2026-11-15
ligament fx convert 1250.00 EUR --to USD --as-of 2026-11-15
ligament fx set EUR USD 1.0845 --from 2026-11-01
```

## CSV export and import

Exports write a money field as two columns: the plain decimal, then `<field>_currency` right after it. Decimals are written exactly. A masked amount is masked in both columns.

```csv
id,name,amount,amount_currency,probability,state,createdAt
cmx3…,Brightwater API rollout,12000.00,USD,10,qualification,2026-11-30T16:59:22.676Z
```

Imports accept the same plain format. They also accept amounts as people type them in spreadsheets: `$1,234.50`, `1.234,50 €`, `USD 1,234.50` and `(12.00)` for a negative amount. The decimal separator is detected per column. A `<field>_currency` column, or an ISO code in the cell, sets the currency. Every row is checked with the API’s rules before anything is written, and problems are reported per row:

```plaintext
Row 14, Amount: USD amounts have at most 2 decimal places (got "12.345")
```

## Manifests

In an [app manifest](https://docs.ligament.ai/developers/app-spec/index.md), a money field declares a fixed `currency` or a `currencyField`, and optionally `scale` and `rounding`:

```ts
{ key: 'amount', label: 'Amount', type: 'money', storage: 'ext', order: 3, currency: 'USD' },
{ key: 'salary', label: 'Salary', type: 'money', storage: 'ext', order: 15, currencyField: 'currency' },
{ key: 'unit_price', label: 'Unit price', type: 'money', storage: 'ext', order: 4, currency: 'USD', scale: 4 },
{ key: 'rate', label: 'Rate', type: 'decimal', storage: 'ext', order: 5, scale: 6, rounding: 'half_up' },
```

`rounding` is `half_even` (the default) or `half_up`, and applies to computed values. A `calculated` field with `formulaOutputType: 'money'` or `'decimal'` takes the same settings, and its formula can use `convert(amount, "USD", date)`. Changing an existing field from `number` or `currency` to `money` in a new version converts the stored values on upgrade. The upgrade preview lists them, and the upgrade is refused (409) if any value wouldn’t convert exactly.
