Skip to main content

Create Expense (v1)

Method & Path

POST /api/v1/admin/expenses

Description

Create a new expense record for the platform. Expenses are used to track platform operational costs such as rent, salaries, utilities, marketing, and other services.

Authentication

Required: Admin authentication with dashboard.view permission.

Headers

Authorization: Bearer <admin_token>
Content-Type: application/json

Request Body

{
"amount": 1500.00,
"date": "2025-01-15T10:30:00.000Z",
"description": "Monthly office rent",
"category": "rent",
"notes": "Paid via bank transfer",
"receiptImage": {
"url": "https://storage.googleapis.com/bucket/admin-expenses/expense-id/receipt-1234567890-abc123.webp",
"path": "admin-expenses/expense-id/receipt-1234567890-abc123.webp",
"width": 1000,
"height": 1000,
"sizeBytes": 50000,
"contentType": "image/webp"
}
}

Request Body Schema

FieldTypeRequiredDescription
amountnumberYesExpense amount in USD (must be > 0)
datedateNoExpense date (defaults to current date/time)
descriptionstringYesExpense description (must not be empty)
categorystringYesExpense category: services, salaries, rent, utilities, marketing, or other
notesstringNoAdditional notes about the expense
receiptImageobjectNoReceipt image information (see Receipt Image Schema below)

Receipt Image Schema

FieldTypeRequiredDescription
urlstringYesPublic URL to the receipt image
pathstringYesServer path to the receipt image
widthnumberNoImage width in pixels
heightnumberNoImage height in pixels
sizeBytesnumberNoImage file size in bytes
contentTypestringYesMIME type of the image (typically image/webp)

Response 201 Created

{
"id": "507f1f77bcf86cd799439011",
"amount": 1500.00,
"date": "2025-01-15T10:30:00.000Z",
"description": "Monthly office rent",
"category": "rent",
"receiptImage": {
"url": "https://storage.googleapis.com/bucket/admin-expenses/expense-id/receipt-1234567890-abc123.webp",
"path": "admin-expenses/expense-id/receipt-1234567890-abc123.webp",
"width": 1000,
"height": 1000,
"sizeBytes": 50000,
"contentType": "image/webp"
},
"notes": "Paid via bank transfer",
"createdBy": "507f1f77bcf86cd799439014",
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z"
}

Common Errors

400 Bad Request:

  • Invalid category value
  • Amount must be greater than 0
  • Description is required and cannot be empty
  • Invalid receipt image format

401 Unauthorized: Missing or invalid authentication token

403 Forbidden: Admin does not have dashboard.view permission

500 Internal Server Error: Server error occurred while creating the expense

Notes

  • The createdBy field is automatically set to the authenticated admin's ID
  • Receipt images should be uploaded using the dedicated upload endpoint (POST /api/v1/admin/expenses/:expenseId/receipt) before creating the expense, or the receipt image metadata can be included in the request body
  • All date values use UTC timezone