Discount
Base path: /api/data/discount
POST /api/data/discount
Create a new discount.
Auth: Session cookie required
Tenant: Scoped via x-tenant-id header (injected as tenantId from request context)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| code | string | No | Discount code (e.g. SAVE10) |
| type | enum | Yes | PERCENT or AMOUNT |
| percent | number | Conditional | Percentage (1–100). Required when type is PERCENT |
| amountCents | number | Conditional | Fixed discount in cents. Required when type is AMOUNT |
| scope | object | No | Targeting scope (see below) |
| lifecycle | object | No | Activation and usage limits (see below) |
Scope object:
| Field | Type | Required | Description |
|---|---|---|---|
| appliesToAll | boolean | No | Apply to all products (default true) |
| productIds | string[] | No | Restrict to specific product IDs |
| roleIds | string[] | No | Restrict to specific role IDs |
| customerIds | string[] | No | Restrict to specific customer IDs |
Lifecycle object (create):
| Field | Type | Required | Description |
|---|---|---|---|
| isActive | boolean | No | Whether the discount is active (default true) |
| startsAt | date | No | Activation date |
| endsAt | date | No | Expiration date (must be after startsAt) |
| usageLimit | number | No | Maximum number of uses |
Response (201)
Returns the created discount record.
Errors
| Status | Condition |
|---|---|
| 400 | Validation error, missing required conditional field, or DiscountError |
GET /api/data/discount/:id
Retrieve a discount by ID.
Auth: Session cookie required
Tenant: Scoped via x-tenant-id header
Response (200)
Returns the discount record.
Errors
| Status | Condition |
|---|---|
| 400 | Operation error |
| 404 | Discount not found |
PATCH /api/data/discount/:id
Update a discount by ID. All fields are optional.
Auth: Session cookie required
Tenant: Scoped via x-tenant-id header
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| code | string | No | Updated discount code |
| type | enum | No | PERCENT or AMOUNT |
| percent | number | No | Updated percentage |
| amountCents | number | No | Updated fixed amount in cents |
| scope | object | No | Updated targeting scope |
| lifecycle | object | No | Updated lifecycle settings |
Response (200)
Returns the updated discount record.
Errors
| Status | Condition |
|---|---|
| 400 | Validation error or DiscountError |
DELETE /api/data/discount/:id
Remove a discount by ID.
Auth: Session cookie required
Tenant: Scoped via x-tenant-id header
Response (204)
No content.
Errors
| Status | Condition |
|---|---|
| 400 | Operation error or DiscountError |