Skip to main content

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

HeaderRequiredDescription
AuthorizationYesBearer <workspace_token>
Content-TypeYesapplication/json

Path Parameters

ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
supplierIdstringYesSupplier 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"
}
FieldTypeRequiredDescription
invoiceNumberstringYesUnique per workspace (trimmed)
totalAmountnumberYesMust be ≥ 0
issueDatestring (date)YesInvoice date (day/date)
dueDatestring (date) or nullNoDue date
descriptionstringNoOptional description
notesstringNoOptional notes
imageUrlstring (URL) or nullNoOptional 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