# POST /api/v2/subscription-types/{subscription_type}/items

Add a template line to a subscription type

- MCP id: subscription-types.items.store
- Scope: api:write:subscription_types
- Permission: subscription_types::create
- Needs the billing feature on your organisation
- Rate cost: 1 unit, write bucket. A write costs the same whatever `view` you ask for.
- Cache-Control: private, no-store

Creates one template line on the subscription type named in the path and returns it in the detail view, with a `Location` header pointing at the flat item path.

The type comes from the path, so `subscription_type_id` is not accepted in the body and a line can never be moved between types. Every field is optional: a POST with an empty body creates a blank line, exactly as plnnrly's form does when a line is added. `subscribable_type` and `subscribable_id` are all-or-nothing and the only accepted type is `subscription_product`: a line can be pointed at a hosting domain or server in plnnrly, and a GET will report that, but not through this API. Nothing on the subscription type itself is recalculated: a type is a blueprint and has no totals. A deleted type answers `404`.

## Parameters
- subscription_type (integer, path): The SubscriptionType's numeric id. Accepts a soft-deleted record.
- view (string, optional): Which field set to render.
- X-Request-Id (header, optional): A correlation id of your own. It is recorded in our logs next to the server's request id but never returned: the response header always carries the server's id. A value that does not match the pattern is discarded silently, never rejected.
- Idempotency-Key (header, optional): A caller-chosen key that makes this POST safe to retry. Replaying it returns the original response with Idempotency-Replayed: true.

## Request body
- name (string or null ≤ 255, optional): Optional label for the template line. plnnrly's form does not show it, so most existing lines carry `null`; it exists for programmatic naming and is what `?q=` searches.
- description (string or null, optional): Invoice-line text template, copied verbatim onto the customer subscription's line and resolved only when that line is invoiced. Placeholder tokens survive the copy unresolved: {{$domain}}, {{$period}}, {{$product}}, {{$customer}}, {{$site}}, {{$server}}, plus the Dutch aliases {{$domein}}, {{$periode}} and {{$klant}}.
- quantity (integer ≥ 1, optional): Number of units the template line carries. Whole units: this is an integer, not the fractional quantity an invoice row uses.
- default_purchase_price (decimal (2 dp) -99999999.99 to 99999999.99, optional): Purchase price per unit, excluding VAT, copied onto a new customer subscription's line. At least -99999999.99. At most 99999999.99.
- default_sales_price (decimal (2 dp) -99999999.99 to 99999999.99, optional): Sales price per unit, excluding VAT, copied onto a new customer subscription's line. This is what eventually bills. At least -99999999.99. At most 99999999.99.
- vat_rate (integer 0 to 100, optional): VAT percentage as a whole number: 21 means 21%.
- subscribable_type (string or null, optional): The record this template line sells, normally a subscription product. Null on a line that sells nothing in particular, and a bare {"id": N} reference with `subscribable_type` of `domain` or `server` on a line pointed at a hosting record, which only plnnrly itself can do. Expanding it with `?include=subscribable` additionally requires `subscription_products` read permission and a token scope covering that prefix. Required when subscribable_id is present.
- subscribable_id (integer or null → SubscriptionProduct.id, optional): The record this template line sells, normally a subscription product. Null on a line that sells nothing in particular, and a bare {"id": N} reference with `subscribable_type` of `domain` or `server` on a line pointed at a hosting record, which only plnnrly itself can do. Expanding it with `?include=subscribable` additionally requires `subscription_products` read permission and a token scope covering that prefix. Required when subscribable_type is present.

Unknown keys are refused with `422` validation-failed, naming the key.

## Response 201
- id (integer, required): Unique identifier.
- subscription_type_id (integer, required, server-assigned): The subscription type this template line belongs to. Taken from the path on create and never writable afterwards: a line cannot be moved to another type.
- subscription_type (Ref or SubscriptionTypeSummary, required): The subscription type this template line belongs to.
- subscribable_type (string or null, required): The kind of record `subscribable` points at; it says which branch of `subscribable` applies.
- subscribable_id (integer or null, required): The id of the record `subscribable` points at.
- subscribable (Ref or SubscriptionProductSummary or null, required): The record this template line sells, normally a subscription product. Null on a line that sells nothing in particular, and a bare {"id": N} reference with `subscribable_type` of `domain` or `server` on a line pointed at a hosting record, which only plnnrly itself can do. Expanding it with `?include=subscribable` additionally requires `subscription_products` read permission and a token scope covering that prefix.
- name (string or null ≤ 255, required): Optional label for the template line. plnnrly's form does not show it, so most existing lines carry `null`; it exists for programmatic naming and is what `?q=` searches.
- description (string or null, required, multiline): Invoice-line text template, copied verbatim onto the customer subscription's line and resolved only when that line is invoiced. Placeholder tokens survive the copy unresolved: {{$domain}}, {{$period}}, {{$product}}, {{$customer}}, {{$site}}, {{$server}}, plus the Dutch aliases {{$domein}}, {{$periode}} and {{$klant}}.
- quantity (integer, required): Number of units the template line carries. Whole units: this is an integer, not the fractional quantity an invoice row uses.
- default_purchase_price (decimal (2 dp), required): Purchase price per unit, excluding VAT, copied onto a new customer subscription's line.
- default_sales_price (decimal (2 dp), required): Sales price per unit, excluding VAT, copied onto a new customer subscription's line. This is what eventually bills.
- vat_rate (integer, required): VAT percentage as a whole number: 21 means 21%.
- sort_order (integer, required, server-assigned): Position of the line within its subscription type, and the default sort key. Assigned on create; there is no way to reorder template lines through the API.
- created_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Creation timestamp.
- updated_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Last-write timestamp; use for incremental sync.
- deleted_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required): Soft-delete timestamp, `null` while live.
- links (SubscriptionTypeItemLinks, required)
  - self (url, required): The canonical URI of this record.

## Errors
- 403 forbidden-by-policy | insufficient-permission | insufficient-token-scope: Forbidden.
- 409 idempotency-key-in-flight | idempotency-key-reused: Conflict.
- 415 unsupported-media-type: Unsupported media type.
- 422 unprocessable-relationship | validation-failed: Unprocessable content.
- 400 idempotency-key-required | invalid-cursor | invalid-query-parameter | malformed-request | unsupported-parameter: Bad request.
- 401 token-expired | unauthenticated: Unauthenticated.
- 404 endpoint-not-found | resource-not-found: Not found.
- 406 not-acceptable: Not acceptable.
- 429 rate-limit-exceeded: Too many requests.
- 500 internal-error: Server error.
- 503 tenant-unavailable: Service unavailable.

## Example
```bash
curl -X POST \
  'https://<your-url>/api/v2/subscription-types/1/items' \
  -H 'Authorization: Bearer <token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: <key>' \
  -d '{
    "name": "Managed hosting",
    "description": "Hosting for {{$domain}} over {{$period}}.",
    "quantity": 1,
    "default_purchase_price": "12.50",
    "default_sales_price": "29.95",
    "subscribable_type": "subscription_product",
    "subscribable_id": 1
  }'
```
