# POST /api/v2/sales-invoices/{sales_invoice}/rows

Add a line to an invoice

- MCP id: sales-invoices.rows.store
- Scope: api:write:sales_invoices
- Permission: sales_invoices::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 line on the invoice named in the path and returns it in the detail view, with a `Location` header pointing at the flat item path.

The invoice comes from the path, so `sales_invoice_id` is not accepted in the body and a line can never be moved between invoices. `vat_rate` defaults to the organisation's configured VAT percentage. `vat_amount` and `total_amount` are server-assigned, always computed from quantity, `unit_price` and `vat_rate`; `total_amount` excludes VAT. The invoice's own subtotal, `vat_total` and total are recalculated from all of its lines in the same transaction. A deleted invoice answers `404`, and a legacy or synced invoice answers `409` `state-conflict`. A caller without `sales_invoices::finalize` also returns the invoice to `pending_approval`, as editing the invoice itself does. `exact_item_id` is optional here as it is in plnnrly, but in an organisation using Exact a line without it fails the whole invoice's sync, and naming an `exact_item_id` does not auto-fill the VAT code, GL account or hourly rate plnnrly would fill in from it.

## Parameters
- sales_invoice (integer or string, path): The SalesInvoice's numeric id. Or its invoice_number, matching `[A-Z]+-[0-9]{2}-[0-9]{5}|L-[0-9]+`. 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 ≤ 255, required): The line label, as printed on the invoice. Exact Online prints this when description is empty.
- quantity (decimal (2 dp) -99999999.99 to 99999999.99, required): Number of units billed. Fractional and signed: a budget row carries hours, and a credit line carries a negative quantity. At least -99999999.99. At most 99999999.99.
- unit_price (decimal (2 dp) -99999999.99 to 99999999.99, required): Price per unit, excluding VAT. This is what actually bills. At least -99999999.99. At most 99999999.99.
- description (string or null, optional): Longer line text. Exact Online prints this in preference to name.
- hourly_rate (decimal (2 dp) or null, optional): Rate plnnrly recomputes `unit_price` from when the aggregated-price toggle is switched on a budget row. Stored exactly as sent and `null` when omitted; it feeds no server-side computation.
- billable_minutes (integer ≥ 0, optional): Minutes of budget time this line settles. Zero on a hand-typed row.
- is_aggregated_price (boolean, optional): True: one line of quantity 1 priced at hours times rate. False: quantity carries the hours and `unit_price` the hourly rate.
- vat_rate (integer 0 to 100, optional): VAT percentage as a whole number: 21 means 21%.
- budget_id (integer or null → Budget.id, optional): Project budget this invoice line settles, when the row was generated from budget hours.
- subscription_item_id (integer or null → SubscriptionItem.id, optional): Subscription line this invoice line was generated from, when the row came out of a subscription renewal rather than being typed by hand.
- exact_item_id (string or null ≤ 255, optional): Exact Online article identifier this line bills against. Empty is accepted, but a row without it fails the whole invoice's Exact sync.
- exact_vat_code (string or null ≤ 255, optional): Exact Online VAT code, by code rather than by id.
- exact_cost_center (string or null ≤ 255, optional): Exact Online cost-centre code.
- exact_gl_account (string or null ≤ 255, optional): Exact Online general-ledger revenue account for this line.

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

## Response 201
- id (integer, required): Unique identifier.
- sales_invoice_id (integer, required, server-assigned): The invoice this line belongs to. Taken from the path on create and never writable afterwards: a line cannot be moved to another invoice.
- sales_invoice (Ref or SalesInvoiceSummary, required): The invoice this line belongs to.
- subscription_item_id (integer or null, required): Subscription line this invoice line was generated from, when the row came out of a subscription renewal rather than being typed by hand.
- budget_id (integer or null, required): Project budget this invoice line settles, when the row was generated from budget hours.
- exact_item_id (string or null ≤ 255, required): Exact Online article identifier this line bills against. Empty is accepted, but a row without it fails the whole invoice's Exact sync.
- exact_vat_code (string or null ≤ 255, required): Exact Online VAT code, by code rather than by id.
- exact_cost_center (string or null ≤ 255, required): Exact Online cost-centre code.
- exact_gl_account (string or null ≤ 255, required): Exact Online general-ledger revenue account for this line.
- name (string ≤ 255, required): The line label, as printed on the invoice. Exact Online prints this when description is empty.
- description (string or null, required, multiline): Longer line text. Exact Online prints this in preference to name.
- quantity (decimal (2 dp), required): Number of units billed. Fractional and signed: a budget row carries hours, and a credit line carries a negative quantity.
- unit_price (decimal (2 dp), required): Price per unit, excluding VAT. This is what actually bills.
- hourly_rate (decimal (2 dp) or null, required): Rate plnnrly recomputes `unit_price` from when the aggregated-price toggle is switched on a budget row. Stored exactly as sent and `null` when omitted; it feeds no server-side computation.
- billable_minutes (integer, required): Minutes of budget time this line settles. Zero on a hand-typed row.
- is_aggregated_price (boolean, required): True: one line of quantity 1 priced at hours times rate. False: quantity carries the hours and `unit_price` the hourly rate.
- vat_rate (integer, required): VAT percentage as a whole number: 21 means 21%.
- vat_amount (decimal (2 dp), required, server-assigned): VAT on this line: quantity times `unit_price` times `vat_rate`, rounded to two decimals. Recomputed by the server whenever one of those three changes.
- total_amount (decimal (2 dp), required, server-assigned): Line total excluding VAT (quantity times `unit_price`), which is the convention the invoice form writes. Recomputed by the server whenever quantity or `unit_price` changes.
- sort_order (integer, required, server-assigned): Position of the line within its invoice, and the default sort key. Assigned on create; there is no way to reorder 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 (SalesInvoiceRowLinks, 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 | state-conflict: 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/sales-invoices/1/rows' \
  -H 'Authorization: Bearer <token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: <key>' \
  -d '{
    "name": "Sprint 42: development",
    "description": "Feature work on the customer portal.",
    "quantity": "12.50",
    "unit_price": "95.00"
  }'
```
