# POST /api/v1/reports

> Generate report

- **Tag:** reports
- **Operation ID:** `generate_report`

## Description

Queue a report for generation and return task ID for tracking.

## Authentication

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

## Request body

Schema: `ReportCreateRequest`

- `report_name` (string · required) — Report type identifier. Must match a supported report_name from the /reports endpoint. Examples: 'master_transactions', 'trial_balance', 'general_ledger', 'profit_and_loss_comparative', 'ar_report', 'cogs_report', 'shareholder_loans'. See GET /reports for the complete list of available report types.
- `period_type` (ReportPeriodType) — Controls how report dates are determined. 'custom' (default): Use start_date/end_date fields directly. 'tax_year': Calculate full fiscal year dates from business's tax_year_end_month config. 'tax_quarter': Calculate quarter dates within a fiscal year. When using tax_year or tax_quarter, the resolved dates will be stored in generation_params.
- `tax_year` (integer) — The tax/fiscal year for period calculation. Required when period_type is 'tax_year' or 'tax_quarter'. Example: 2026. The actual date range depends on the business's tax_year_end_month setting. For a business with tax year ending March 31, tax_year=2026 covers April 1, 2025 through March 31, 2026.
- `tax_quarter` (integer) — The quarter within the tax year (1-4). Required when period_type is 'tax_quarter'. Q1 is the FIRST quarter of the fiscal year, which may start in the prior calendar year for non-calendar fiscal years. Example: For a March fiscal year-end, Q1 of tax_year=2026 covers April 1-June 30, 2025.
- `start_date` (string) — Report period start date in YYYY-MM-DD format (e.g., '2026-01-01'). Required when period_type='custom' for reports with input_type='date_start_end' or similar. Ignored when period_type is 'tax_year' or 'tax_quarter' (dates calculated automatically).
- `end_date` (string) — Report period end date in YYYY-MM-DD format (e.g., '2026-12-31'). Required when period_type='custom' for date-range reports. For point-in-time reports (input_type='date_end_only'), only end_date is needed. Ignored when period_type is 'tax_year' or 'tax_quarter'.
- `comparison_period_type` (ReportPeriodType) — Period type for the comparison/prior period in comparative reports. Same options as period_type: 'custom', 'tax_year', or 'tax_quarter'. Used with reports like 'profit_and_loss_comparative' and 'balance_sheet_comparative' to enable variance analysis between two periods.
- `comparison_tax_year` (integer) — Tax year for the comparison period. Used when comparison_period_type is 'tax_year' or 'tax_quarter'. Example: Set to 2025 to compare against the current period's 2026 for year-over-year analysis.
- `comparison_tax_quarter` (integer) — Quarter (1-4) for the comparison period. Required when comparison_period_type is 'tax_quarter'. Example: comparison_tax_quarter=1 with comparison_tax_year=2025 compares Q1 2025 against the current period.
- `comparison_start_date` (string) — Start date for comparison period in YYYY-MM-DD format. Used when comparison_period_type='custom' for comparative reports. Example: '2025-01-01' to compare against prior year.
- `comparison_end_date` (string) — End date for comparison period in YYYY-MM-DD format. Used when comparison_period_type='custom' for comparative reports. Example: '2025-12-31' to compare full prior year.
- `ledger_id` (string) — UUID of a specific ledger account to filter the report. Currently used with 'general_ledger' report to show transactions for only one account instead of all accounts. When omitted, the general_ledger report includes all accounts. Example: '019ab37c-1ed6-7000-8000-000000000001'.
- `instance_id` (string) — Legacy ledger-engine instance override. Optional and normally omitted; reports run against the business's own books.
- `file_s3_key` (string) — S3 object key for file-based report inputs. Required for reports with input_type='file_upload' (e.g., 'cogs_report'). The file should be uploaded first via the upload endpoint. Example: 'uploads/business-123/cogs-data-2026.csv'.
- `s3_keys` (array · string) — Array of S3 object keys when a report requires multiple input files. Each key should reference a previously uploaded file. Example: ['uploads/business-123/sales-q1.csv', 'uploads/business-123/sales-q2.csv'].
- `tag_group_id` (string) — UUID of a specific tag group to filter the report. Used with 'pnl_by_department' to segment by tags within this group.
- `tag_ids` (array · string) — List of specific tag UUIDs to filter the report. When multiple tags are provided for 'pnl_by_department', it generates a multi-sheet report with one P&L statement per tag.
- `additional_params` (object) — Report-specific parameters that vary by report type. Supported parameters: **customer_id** (UUID): Filter customer_statements or pnl_by_customer to a specific customer. **vendor_id** (UUID): Filter vendor_statements to a specific vendor. **include_zero_balances** (bool): Include zero-balance accounts in trial_balance report. **tag_group_id** (UUID): Filter pnl_by_department to tags in a specific tag group. **forecast_days** (int): Number of days to forecast in cash_flow_forecast (default: 90). **raw** (bool): For general_ledger only — return a single flat sheet with no formatting or headers (default: false). **include_period_columns** (bool): Any report — insert a '<column> Quarter Ending' and a '<column> Calendar Year Ending' column immediately after every date column in the file (e.g. a 02/14/2026 Date yields Date Quarter Ending 03/31/2026 and Date Calendar Year Ending 12/31/2026). Calendar quarters/years, formatted like the source date column; applies to xlsx, csv and html output (default: false). **basis** ('accrual' | 'cash'): Accounting basis for the reports that support one. Omitted means the business's configured default, which may be cash — it is not always accrual. The generated file states the basis it was built on and the stored report record records it. Example: {'customer_id': '019abc-uuid', 'include_zero_balances': true}, {'include_period_columns': true}, {'basis': 'cash'}.
- `visible_to_client` (boolean) — Whether the finished report appears in the client portal. Omit for the report's default: confidential deliverables (the Quality of Earnings Workbook) stay internal to the firm, everything else is shared. Can be changed later with PATCH /reports/{report_id}.
- `output_format` (ReportOutputFormat) → `ReportOutputFormat` — Output file format for the report. 'xlsx' (default): Excel format with formatting, multiple tabs, headers, and currency formatting. 'csv': Comma-separated values format as a single flat file without formatting. 'html': HTML format. CSV is useful for importing into other systems or programmatic analysis.

## Example request

```json
{
  "summary": "Custom date range",
  "value": {
    "end_date": "2026-03-31",
    "period_type": "custom",
    "report_name": "profit_and_loss",
    "start_date": "2026-01-01"
  }
}
```

## Responses

### 202 — Successful Response

Schema: `SuccessEnvelope_ReportTaskResponse_`

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

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

### 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/reports' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "summary": "Custom date range",
  "value": {
    "end_date": "2026-03-31",
    "period_type": "custom",
    "report_name": "profit_and_loss",
    "start_date": "2026-01-01"
  }
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/reports', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "summary": "Custom date range",
  "value": {
    "end_date": "2026-03-31",
    "period_type": "custom",
    "report_name": "profit_and_loss",
    "start_date": "2026-01-01"
  }
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {'summary': 'Custom date range',
 'value': {'end_date': '2026-03-31',
           'period_type': 'custom',
           'report_name': 'profit_and_loss',
           'start_date': '2026-01-01'}}

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

## See also

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