# POST /api/v1/accounting-periods/bulk-lock

> Bulk close-and-lock accounting periods

- **Tag:** accounting-periods
- **Operation ID:** `bulk_lock_periods_api_v1_accounting_periods_bulk_lock_post`

## Description

Close and lock multiple accounting periods in one call. Designed for historical-data migration: any open period in the list is closed first, then transitioned to locked. Already-locked periods are skipped.

## Authentication

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

## Request body

Schema: `BulkLockPeriodsRequest`

- `period_ids` (array · string · required) — Period UUIDs to lock
- `lock_reason` (string) — Reason recorded on each period. Defaults to 'Historical migration - bulk locked' when omitted.

## Responses

### 201 — Successful Response

Schema: `BulkLockPeriodsResult`

- `locked_count` (integer · required) — Periods that ended up locked
- `skipped_count` (integer · required) — Periods skipped (already locked / not found)
- `locked_ids` (array · string)
- `skipped` (array · object) — Per-period skip info: {period_id, reason}

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

### 403 — Forbidden - Insufficient permissions

### 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/accounting-periods/bulk-lock' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "period_ids": []
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/accounting-periods/bulk-lock', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "period_ids": []
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {
  "period_ids": []
}

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

## See also

- HTML version: https://www.ondayzero.com/docs/reference/accounting-periods/bulk-lock-periods
- OpenAPI slice: https://www.ondayzero.com/docs/reference/accounting-periods/bulk-lock-periods/openapi.json
- Other endpoints in **accounting-periods**: https://www.ondayzero.com/docs/reference/accounting-periods
