# POST /api/v1/deferred-revenue/invoices/{invoice_id}

> Defer an invoice

- **Tag:** deferred-revenue
- **Operation ID:** `defer_invoice`

## Description

Route an invoice's revenue to Deferred Revenue and schedule it.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Parameters

- `invoice_id` (path, string, required)

## Request body

Schema: `DeferInvoiceRequest`

- `deferred_amount_cents` (integer) — Amount routed to Deferred Revenue. Defaults to the invoice's revenue (total excluding sales tax); may not exceed it.
- `unit` (DeferralUnitEnum) → `DeferralUnitEnum` — Denominator unit: months, hours or custom
- `method` (DeferralMethodEnum) → `DeferralMethodEnum` — straight_line auto-populates every numerator; custom leaves them for the user and posts nothing until they are filled in.
- `period_count` (integer · required) — Number of monthly recognition periods
- `total_units` (number | string) — Denominator quantity (e.g. 400 hours). Defaults to period_count for the months unit.
- `start_date` (string · date) — First recognition period (defaults to today's month)
- `revenue_ledger_name` (string) — Revenue account the recognition entries credit. Defaults to the account the invoice itself booked revenue to.
- `periods` (array · DeferralPeriodInput) — Optional per-period numerators for a custom schedule. Length must match period_count when supplied.
- `notes` (string)

## Example request

```json
{
  "method": "straight_line",
  "notes": "Annual support contract recognized monthly",
  "period_count": 12,
  "start_date": "2026-02-01",
  "unit": "months"
}
```

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_InvoiceDeferralResponse_`

- `success` (boolean)
- `message` (string)
- `code` (string)
- `data` (InvoiceDeferralResponse)

### 400 — Bad Request - Invalid input

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 401 — Unauthorized - Missing or expired token, an MCP OAuth token used against the REST API, or no access to this business

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 403 — Forbidden - Insufficient permissions

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 404 — Not Found - Resource does not exist

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 409 — Conflict - Resource already exists or is in an incompatible state

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 422 — Validation Error

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/deferred-revenue/invoices/{invoice_id}' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "method": "straight_line",
  "notes": "Annual support contract recognized monthly",
  "period_count": 12,
  "start_date": "2026-02-01",
  "unit": "months"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/deferred-revenue/invoices/{invoice_id}', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "method": "straight_line",
  "notes": "Annual support contract recognized monthly",
  "period_count": 12,
  "start_date": "2026-02-01",
  "unit": "months"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {'method': 'straight_line',
 'notes': 'Annual support contract recognized monthly',
 'period_count': 12,
 'start_date': '2026-02-01',
 'unit': 'months'}

response = httpx.post("https://api.ondayzero.com/api/v1/deferred-revenue/invoices/{invoice_id}", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/deferred-revenue/defer-invoice
- OpenAPI slice: https://www.ondayzero.com/docs/reference/deferred-revenue/defer-invoice/openapi.json
- Other endpoints in **deferred-revenue**: https://www.ondayzero.com/docs/reference/deferred-revenue (markdown bundle: https://www.ondayzero.com/docs/reference/deferred-revenue.md, OpenAPI: https://www.ondayzero.com/docs/reference/deferred-revenue/openapi.json)
- Endpoint catalog: https://www.ondayzero.com/docs/reference/index.md
