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

# Create a subscription

> Create a subscription with its steps in one request, check it with the preview first, and plan a discount that is on the first invoice.

A subscription is created with `POST /api/subscriptions`. The body names the customer, the contract terms and the contract's **steps**: each step has a key, a trigger (when it takes effect), a settlement and the operations of the change API (`add_line`, `update_price`, `add_discount` and the others). `POST /api/subscriptions/preview` takes the same body, answers what the steps would invoice and stores nothing.

> [!NOTE]
>
> Both routes need the permission `subscription:write` and subscription changes switched on for the organisation. Without the permission they answer `403`; with subscription changes switched off, `403` with the code `SUBSCRIPTION_CHANGE__DISABLED`.

## A contract with a discount from the first invoice

The example starts a contract on 01.12.2026 with one line at 100.00 EUR a month and 10 % on all products for good. A discount without `items` in the step that starts the contract applies from that step's day, so the first invoice already carries it.

```bash theme={null}
curl -X POST "$BASE_URL/api/subscriptions/preview" \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "0199c0de-0000-7000-8000-00000000c001",
    "contract": {
      "start": "2026-12-01",
      "term": { "initialTerm": "P12M", "renewalTerm": "P12M", "noticePeriod": "P3M" }
    },
    "steps": [
      {
        "key": "start",
        "trigger": { "type": "at", "date": "2026-12-01" },
        "operations": [
          { "type": "add_line", "key": "flat", "productId": "0199c0de-0000-7000-8000-0000000000a1", "priceId": "0199c0de-0000-7000-8000-0000000000b1", "name": "Flat" },
          { "type": "add_discount", "discount": { "type": "percentage", "percent": "10" }, "duration": { "type": "forever" } }
        ]
      }
    ]
  }'
```

The preview shows one document on 01.12.2026 with a net of 90.00 EUR. Sent to `POST /api/subscriptions`, the same body answers `201`, and the contract bills 90.00 EUR on 01.12.2026, 01.01.2027 and 01.02.2027.

| Discount in the start step | First invoice | Later invoices |
| - | - | - |
| 10 % on the line (`items: [{"key": "flat"}]`) | 90.00 | 90.00 |
| 10 % on all products (no `items`) | 90.00 | 90.00 |
| 20.00 EUR once on the line (`"amount": {"value": 2000, "currency": "EUR"}`, duration `once`) | 80.00 | 100.00 |
| 10 % for three periods (duration `cycles`, 3) | 90.00 | 90.00 on 01.01. and 01.02.2027, 100.00 from 01.03.2027 |

A discount on all products reaches every line that bills by period. A one-time line keeps its price: a setup of 100.00 EUR next to the line in the example makes a first invoice of 190.00 EUR.

## Later steps

A later step is dated (`{"type": "at", "date": "2027-01-01"}`), follows an earlier step of the body by an offset (`{"type": "after", "step": "start", "offset": "P6M"}`) or waits until it is executed by its key (`{"type": "manual"}`). It names a line of an earlier step by the key of its `add_line`, for example `{"item": {"key": "flat"}}`.

* A step dated on the contract start day takes effect after the step that starts the contract, so it can change that step's lines: a second step on 01.12.2026 with 10 % on `flat` bills 90.00 EUR on 01.12.2026 and in every month after.
* A step that adds a line together with a discount on all products bills that line with the discount from the step's day: a step on 01.01.2027 that adds a support line at 20.00 EUR a month and gives 10 % on all products bills 108.00 EUR for January (90.00 and 18.00).

## After the create

The answer lists the steps as `GET /api/subscriptions/{subscriptionId}/steps` does, with `revocable`, `editable` and `notEditableReason` per step. A pending step is changed with `PUT /api/subscriptions/{subscriptionId}/steps/{key}` and taken back with `DELETE /api/subscriptions/{subscriptionId}/steps/{key}`. While the contract has not started (a step marked `startsContract` waits for its execution), `PUT /api/subscriptions/{subscriptionId}/steps` writes every step of the draft again in one request.

The body of that request restates every step of the draft, the unchanged ones too, and a later step is planned on the new version of the step it builds on; `POST /api/subscriptions/{subscriptionId}/steps/preview` shows each step as the `PUT` would plan it. Every step the body changes is still pending and is invoiced only when it takes effect, so a later step bills on the new version from its first invoice. Example: a draft whose go-live adds 10 licences at 100.00 EUR a year and whose step `mehr` raises them to 12 two months after the go-live is saved on 20.11.2026 with 11 licences in the go-live and `mehr` unchanged. The go-live on 01.12.2026 invoices 1,100.00 EUR, and `mehr` on 01.02.2027 bills the one licence more: 1 × 100.00 × 303/365 = 83.01 EUR, where the draft before the edit bills 2 × 100.00 × 303/365 = 166.03 EUR. The draft is saved as a whole: a refused body leaves every step as it was.

Once the contract runs, each pending step is changed with a request of its own to `PUT /api/subscriptions/{subscriptionId}/steps/{key}`, in the order the requests are sent. Each request stands alone, so a refusal leaves the steps changed before it changed. That route refuses the change of a step that a later pending step builds on (`409`, `reason` `later_step`), where the draft edit plans the later step on the new version.

The phases, the triggers and the draft edit are described in detail, in German, in [Vertragsphasen über die API](https://docs.fynn.eu/guide/developers/contract-steps-api.md); changes of a running contract in [Mengen ändern](https://docs.fynn.eu/guide/developers/quantity-changes-api.md). Every field is in the API reference of `POST /api/subscriptions`.
