Create Invoice
The POST endpoint creates a new invoice for an existing order with the specified details.
Endpoint
- URL:
/invoices - Method:
POST
Authentication
- Header:
accessToken - Type: Bearer Token
- Value:
<ACCESS-TOKEN>
Request Headers
| Header | Type | Description |
|---|---|---|
Content-Type | string | Must be application/json. |
accessToken | string | Access token for authentication. (required) |
Request Body
The request body must include the order ID for which the invoice will be generated. The invoice details (line items, total, etc.) are automatically generated based on the order information.
| Field | Type | Requirements/Notes |
|---|---|---|
orderId | string | Required - Unique identifier for the order to generate invoice for. |
Sample Request Body
{
"orderId": "69ab24db449866373d5e3e35"
}
Response
- Status Code: 201 Created
Success Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates whether the invoice was created. |
data | object | The created invoice object. |
message | string | Success message. |
Sample Response Body
{
"success": true,
"data": {
"order": "6932f96b8cd64c28a4fb5873",
"entityId": "1",
"lineItems": [
{
"lineItemId": "6932f96b8cd64c28a4fb5876",
"quantity": 30,
"id": "693738682fa9114d9af87d2a"
},
{
"lineItemId": "6932f96b8cd64c28a4fb5877",
"quantity": 20,
"id": "693738682fa9114d9af87d2b"
},
{
"lineItemId": "6932f96b8cd64c28a4fb5878",
"quantity": 10,
"id": "693738682fa9114d9af87d2c"
},
{
"lineItemId": "6932f96b8cd64c28a4fb5879",
"quantity": 5,
"id": "693738682fa9114d9af87d2d"
},
{
"lineItemId": "6932f96b8cd64c28a4fb587a",
"quantity": 2,
"id": "693738682fa9114d9af87d2e"
}
],
"total": 3684.78,
"createdBy": {
"id": "6852dc137d290c8e310f258e",
"name": "Sam Nabahani",
"type": "admin"
},
"metaFields": [],
"createdAt": "2025-12-08T20:43:20.608Z",
"updatedAt": "2025-12-08T20:43:20.608Z",
"id": "693738682fa9114d9af87d29"
}
}
Example Request
curl --location --request POST '<BASE-URL>/invoices' \
--header 'Content-Type: application/json' \
--header 'accessToken: <ACCESS-TOKEN>' \
--data-raw '{
"orderId": "69ab24db449866373d5e3e35"
}'
Error Responses
400 Bad Request
{
"success": false,
"message": "Validation error: orderId is required"
}
404 Not Found
{
"success": false,
"message": "Order not found"
}
401 Unauthorized
{
"success": false,
"message": "Invalid or missing access token"
}
500 Internal Server Error
{
"success": false,
"message": "An error occurred while creating the invoice"
}