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

> Defer an invoice

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

## 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)

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_InvoiceDeferralResponse_`

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

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

### 403 — Forbidden - Insufficient permissions

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

### 409 — Conflict - Resource already exists

### 422 — Validation Error

Schema: `HTTPValidationError`

- `detail` (array · ValidationError) → `ValidationError`
  - `loc` (array · string | integer · required)
  - `msg` (string · required)
  - `type` (string · required)
  - `input` (object)
  - `ctx` (object)

## 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 '{
  "period_count": 0
}'
```

### 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({
  "period_count": 0
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {
  "period_count": 0
}

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
