> ## Documentation Index
> Fetch the complete documentation index at: https://docs.streamlinedpayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bill in milestones

> Split an issued invoice into stages, change them as the work progresses, and handle each error Update invoice returns.

Use milestones to bill one invoice in stages, such as a deposit now and the rest on delivery. Each milestone is issued on its own schedule, and your customer pays only what's been issued. Milestone billing needs a Streamlined plan that includes it.

Set an invoice's milestones with [Update invoice](https://docs.streamlinedpayments.com/api-reference/invoices/update-invoice.md), and read them with [Get invoice details](https://docs.streamlinedpayments.com/api-reference/invoices/get-invoice-details.md).

## Read the milestones

Get invoice details, Create invoice from order, and Update invoice all return `billing_milestones`, oldest first:

```json theme={null}
{
  "invoice": {
    "uuid": "8f6c2a1e-4b7d-4c3e-9a51-2d0f6b7e1c94",
    "amount": 300000,
    "billing_milestones": [
      { "id": 48212, "name": "Deposit", "amount": 100000, "amount_type": "fixed", "due_date": "2026-12-01", "has_been_issued": true, "current_open_balance": 0 },
      { "id": 48213, "name": "Delivery", "amount": 200000, "amount_type": "fixed", "due_date": null, "has_been_issued": false, "current_open_balance": 200000 }
    ]
  }
}
```

Send `id` back to change or remove a milestone. Voided milestones aren't listed.

## Change the milestones

Send `billing_milestones_attributes` to Update invoice. Each item changes one milestone:

* **Change one:** send its `id` and the fields you're changing.
* **Add one:** leave out `id`.
* **Remove one:** send its `id` with `_destroy: true`.

```bash theme={null}
curl -X PUT https://api.streamlinedpayments.com/api/v1/invoices/8f6c2a1e-4b7d-4c3e-9a51-2d0f6b7e1c94 \
  -H "X-App-Id: $STREAMLINED_APP_ID" \
  -H "X-Api-Key: $STREAMLINED_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "billing_milestones_attributes": [
      { "id": 48213, "name": "Delivery", "amount": 150000, "amount_type": "fixed" },
      { "name": "Sign-off", "amount": 50000, "amount_type": "fixed", "net_terms": 30, "issue_method": "MANUAL" }
    ]
  }'
```

These rules decide what's saved:

* **Milestones must add up to the total.** Streamlined checks the milestones as they'd be after your change: the ones you send, plus every one you leave out at its saved amount. Together they must equal the invoice total, or 100% when every milestone is a percentage. Leaving a milestone out keeps it. It doesn't remove it.
* **Issued milestones can't change.** If you change one or send it with `_destroy: true`, the request still gets a `200` and the milestone stays as it was. Its saved amount counts toward the total.
* **Voided milestones are skipped.** They aren't listed. If you send the `id` of one you read before it was voided, Streamlined skips that item and saves the rest of the request. Voided milestones don't count toward the total.
* **Send each milestone once.** Sending the same `id` in two items is refused with `duplicate_milestone`.
* **Dates you send can't be in the past.** Only the dates in an item are checked. An item with no `issued_at` and no `due_date` isn't checked, so neither item in the example above is. An item's due date is its `due_date`, or `issued_at` plus `net_terms` days when it has no `due_date`. Its issue and due dates must be today or later, and no earlier than those of the items before it in the request. Issued milestones keep their dates.
* **It's all or nothing.** If Streamlined refuses the request, nothing on the invoice changes, including the due date, memo, and PO number.

`id` can be a number or a string of the same digits. To send a single milestone, you can use one object instead of a list. `_destroy` removes the milestone when it's `true`, `"true"`, `"1"`, or `1`, and does nothing when it's `false`, `"false"`, `"0"`, or empty.

## When milestones are issued

`issue_method` decides when a milestone is issued:

| `issue_method` | Issued |
| - | - |
| `SPECIFIED` | On its `issued_at` date, emailed to your customer. Streamlined checks every 15 minutes. Without `issued_at`, the schedule never issues it. |
| `MANUAL` | Only from the Streamlined app, when the merchant clicks **Issue now**. They can edit the email's subject and message, or skip the email. |
| `WITH_INVOICE` | With the invoice. Don't add one to an invoice that's already issued. Use `SPECIFIED` or `MANUAL` there. |

The API and the AI assistant tools can't issue a milestone.

When the invoice is paid in full, every milestone not yet issued is issued, without an email. That includes a `SPECIFIED` milestone with no `issued_at`.

`due_date` is set like this:

* **When a milestone is added:** a `SPECIFIED` milestone with an `issued_at` and `net_terms` above `0` gets `issued_at` plus `net_terms` days. Any other milestone keeps the `due_date` you send, or null if you don't send one.
* **When a milestone is changed:** it keeps the `due_date` you send. Nothing is recalculated until it's issued.
* **When a milestone is issued:** with `net_terms` above `0`, it becomes the issue date plus `net_terms` days, replacing any date saved before. With `net_terms` of `0`, it keeps its saved `due_date`, or becomes the issue date if there isn't one.

## Errors

When Update invoice refuses a request, it returns `422` and changes nothing. Show people `error`, and branch on `code`:

```json theme={null}
{
  "error": "Milestone 48213 isn't on this invoice. Reload the invoice and try again.",
  "code": "milestone_not_on_invoice"
}
```

| `code` | What happened | What to do |
| - | - | - |
| `plan_required` | The account's plan doesn't include milestone billing. | Ask the merchant to choose a plan that includes it in **Settings > Plans & Billing** in Streamlined, or send the request without `billing_milestones_attributes`. |
| `milestone_not_on_invoice` | A milestone `id` isn't one of this invoice's milestones. It may have been removed since you read it. | Get the invoice again and use the IDs it returns. |
| `milestone_totals_mismatch` | The milestones don't add up to the invoice total, counting the ones you left out and the issued ones at their saved amounts. | Change the amounts so they add up, or remove the milestones you no longer need. |
| `milestone_amount_invalid` | An amount is zero or less, or a percentage is outside 1 to 100. | Fix that milestone's `amount`. |
| `milestone_date_invalid` | A milestone you added or changed has an issue or due date in the past, or the dates are out of order. | Use dates of today or later, with each milestone no earlier than the one before. |
| `duplicate_milestone` | The same milestone `id` is in more than one item. | Send each milestone once, with all its changes in one item. |
| `invalid_milestone` | A milestone couldn't be saved, for example because its `name` is blank. `error` says why. | Fix that milestone and send the request again. |
| `invalid_invoice` | The invoice couldn't be saved, for example because `due_date` isn't a date. `error` says why. | Fix that field and send the request again. |
| `order_deleted` | The order this invoice was created from was deleted, so the invoice can't be changed. | Contact Streamlined support to restore the order. Don't retry unchanged. |

Treat any `code` you don't recognize like a `422` without one: show `error` and don't retry unchanged.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.