Create Supplier Invoice (v1)
Method & Path
POST /api/v1/workspace/:workspaceId/suppliers/:supplierId/invoices
Actual backend path: POST /v1/workspace/:workspaceId/suppliers/:supplierId/invoices
Description
Create a new invoice for a supplier (الفاتورة باليوم والتاريخ). Invoice number must be unique within the workspace.
Authentication
Required: Workspace JWT.
Persona access
- Workspace Owner: Allowed (suppliers section enabled for workspace).
- Staff: Allowed when suppliers access is granted via workspace menu/permissions.
- Admin / Customer: Not applicable for this client workspace API.
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <workspace_token> |
Content-Type | Yes | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | Workspace identifier |
supplierId | string | Yes | Supplier identifier |
Request Body
{
"invoiceNumber": "INV-001",
"totalAmount": 5000,
"issueDate": "2024-01-15",
"dueDate": "2024-02-15",
"description": "وصف اختياري",
"notes": "ملاحظات",
"imageUrl": "https://storage.googleapis.com/bucket/path/to/image.webp"
}
| Field | Type | Required | Description |
|---|---|---|---|
invoiceNumber | string | Yes | Unique per workspace (trimmed) |
totalAmount | number | Yes | Must be ≥ 0 |
issueDate | string (date) | Yes | Invoice date (day/date) |
dueDate | string (date) or null | No | Due date |
description | string | No | Optional description |
notes | string | No | Optional notes |
imageUrl | string (URL) or null | No | Optional scanned invoice image; upload via Upload supplier invoice image first, then pass the returned url |
note
To attach an image, call POST .../suppliers/:supplierId/invoice-image with multipart field file, then include the returned HTTPS URL in imageUrl.
Response 201 Created
{
"invoice": {
"id": "507f1f77bcf86cd799439021",
"workspaceId": "507f1f77bcf86cd799439012",
"supplierId": "507f1f77bcf86cd799439011",
"invoiceNumber": "INV-001",
"totalAmount": 5000,
"paidAmount": 0,
"remainingAmount": 5000,
"status": "pending",
"issueDate": "2024-01-15T00:00:00.000Z",
"dueDate": "2024-02-15T00:00:00.000Z",
"description": "وصف اختياري",
"notes": "ملاحظات",
"imageUrl": null,
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-01-15T10:00:00.000Z"
}
}
Common Errors
- 400 Bad Request: Validation error
- 409 Conflict: Invoice number already exists in workspace
- 401 Unauthorized: Missing or invalid token
- 403 Forbidden: Workspace access denied
- 404 Not Found: Workspace or supplier not found
- 500 Internal Server Error: Server error