# POST /api/v1/invoices/bulk

> Bulk create invoices

- **Tag:** invoices
- **Operation ID:** `create_bulk_invoices`

## Description

Create multiple invoices from CSV data in a single request.

## Authentication

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

## Request body

Schema: `InvoiceBulkRequest`

- `s3_key` (string) — S3 key of the uploaded CSV file containing invoice data.
- `finalize` (boolean) — If true, finalize the created invoices. Needs a connected Stripe account, except with `historical`: then every row is finalized locally (no Stripe, no email), its entry dated on the row's `invoice_date`, which every invoice must then have.
- `allow_duplicates` (boolean) — By default a row that matches an invoice a previous import already created (same customer, due date, total, description and line items) is skipped and reported under `duplicates`, so uploading the same file twice is safe. Set true to import those rows anyway — they are created without a fingerprint and will not be deduplicated against on future uploads.
- `historical` (boolean) — The file holds invoices that were already issued elsewhere — a books migration rather than new billing. Every row is written locally and none reach Stripe, even if the business has an account connected, so nothing can be sent to or charged to a customer. Past due dates are accepted, which they otherwise are not. Use the `invoice_date` and `invoice_number` columns to keep each invoice's original date and number. The invoices are never chased by the AR dunning emails. With `finalize`, each is finalized locally and its entry (debiting the customer's AR) posts on its `invoice_date`, floored at the books' start date.
- `preview` (boolean) — Run every check (customers, SKUs, projects, dates, amounts, duplicates, invoice numbers) and report what would be imported, without creating anything or calling Stripe. `would_create` counts the invoices that pass; `failed` lists the rest with suggestions.
- `allow_partial` (boolean) — By default a row that fails validation refuses the whole file (400 VALIDATION_574, nothing created). Set true to import the invoices that validate and report the failed rows for a retry.

## Example request

```json
{
  "allow_duplicates": false,
  "finalize": false,
  "historical": false,
  "s3_key": "uploads/invoices/batch-2024-01.csv"
}
```

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_InvoiceBulkCreateResponse_`

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

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

### 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/invoices/bulk' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "allow_duplicates": false,
  "finalize": false,
  "historical": false,
  "s3_key": "uploads/invoices/batch-2024-01.csv"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/invoices/bulk', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "allow_duplicates": false,
  "finalize": false,
  "historical": false,
  "s3_key": "uploads/invoices/batch-2024-01.csv"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {'allow_duplicates': False,
 'finalize': False,
 'historical': False,
 's3_key': 'uploads/invoices/batch-2024-01.csv'}

response = httpx.post("https://api.ondayzero.com/api/v1/invoices/bulk", headers=headers, json=payload)
data = response.json()
```

## See also

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