API Documentation
Overview
The Expense Management API provides comprehensive functionality for managing business expenses and expense categories within the Bee O'clock panel service. This module handles the complete expense lifecycle, including creation, updates, categorization, deletion, and detailed tracking of expense items with multi-currency support.
Base Configuration
Authentication
All endpoints require Bearer token authentication.
Headers
Authorization: Bearer <token>- Required for all endpointsx-business-tenant-id: <tenant_id>- Required for multi-tenancy supportContent-Type: application/json- For POST/PUT requests
Base URL
/api/v1/expenseExpense Endpoints
1. Get Paginated Expenses
Endpoint: GET /api/v1/expense/paged
Description: Retrieves a paginated list of expenses with advanced filtering capabilities.
Query Parameters:
Response:
Example Request:
Example Response:
2. Get Expense by ID
Endpoint: GET /api/v1/expense/{id}
Description: Retrieves a specific expense by its ID with permission validation.
Path Parameters:
id(string, required) - Expense ID
Response: ExpenseDto
Example Request:
Example Response:
3. Create Expense
Endpoint: POST /api/v1/expense
Description: Creates a new expense with validation and permission checks.
Request Body: ExpenseDto
Response: ExpenseDto
Example Request:
Example Response:
4. Update Expense
Endpoint: PUT /api/v1/expense/{id}
Description: Updates an existing expense with validation and permission checks.
Path Parameters:
id(string, required) - Expense ID
Request Body: ExpenseDto
Response: ExpenseDto
Example Request:
5. Delete Expense
Endpoint: DELETE /api/v1/expense/{id}
Description: Deletes an expense with permission validation.
Path Parameters:
id(string, required) - Expense ID
Response: void (204 No Content)
Example Request:
Expense Category Endpoints
1. Get Paginated Expense Categories
Endpoint: GET /api/v1/expense/category/paged
Description: Retrieves a paginated list of expense categories.
Query Parameters:
Response:
Example Request:
Example Response:
2. Create Expense Category
Endpoint: POST /api/v1/expense/category
Description: Creates a new expense category with validation.
Request Body: ExpenseCategoryDto
Response: void (201 Created)
Example Request:
3. Create Multiple Expense Categories
Endpoint: POST /api/v1/expense/category/bulk
Description: Creates multiple expense categories in a single request.
Request Body: ExpenseCategoryDto[]
Response: void (201 Created)
Example Request:
Data Models
ExpenseDto
ExpenseValueDto
ExpenseItemDto
ExpenseSourceDto
ExpenseCategoryDto
ExpensePaginationDto
Enums
ExpenseSourceTypeEnum
CurrencyCodeEnum
Error Handling
Common Error Responses
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
409 Conflict
422 Unprocessable Entity
Business Rules
Expense Creation
Amount Validation: Total expense amount must be positive and match sum of line items
Date Validation: Expense date is required and must be a valid ISO date string
Currency Consistency: All line items must use the same currency as the total
Category Validation: All categories must exist in the expense category collection
Source Validation: All sources must reference valid entities (members, products, suppliers)
Expense Updates
Amount Recalculation: Total amount is automatically recalculated from line items
Category Integrity: Categories must remain valid and existing
Source Integrity: Source references must remain valid
Audit Trail: All changes are tracked for compliance and auditing
Permission Validation: User must have appropriate permissions for updates
Expense Deletion
Soft Delete: Expenses are marked as deleted rather than physically removed
Audit Preservation: All historical data is maintained for compliance
Reference Integrity: Related data references are handled appropriately
Permission Requirements: User must have delete permissions
Category Management
Name Uniqueness: Category names must be unique within the tenant
Usage Tracking: Cannot delete categories that are currently used in expenses
Bulk Operations: Support for efficient bulk category creation
Predefined Categories: System provides predefined categories for common expense types
Permission Requirements
Expense Operations:
READ_EXPENSE- View expensesCREATE_EXPENSE- Create new expensesEDIT_EXPENSE- Update existing expensesDELETE_EXPENSE- Delete expenses
Category Operations:
READ_EXPENSE_CATEGORY- View expense categoriesCREATE_EXPENSE_CATEGORY- Create new categoriesEDIT_EXPENSE_CATEGORY- Update existing categoriesDELETE_EXPENSE_CATEGORY- Delete categories
Performance Considerations
Pagination
Default page size: 10 items
Maximum page size: 100 items
Use pagination for large expense lists
Filtering and Search
Date range filtering optimized with database indexes
Text search across expense descriptions
Category-based filtering with array operations
Multi-currency support for international businesses
Caching
Expense category data is heavily cached due to infrequent changes
Recent expenses cached for dashboard displays
Search result caching for common queries
Database Optimization
Compound indexes on date ranges and categories
Text indexes for description search
Optimized aggregation for expense totals and reports
Rate Limiting
Read Operations: 100 requests per minute per user
Write Operations: 30 requests per minute per user
Bulk Operations: 10 requests per minute per user
Monitoring and Logging
Request Logging
All API requests are logged with:
Request ID for tracing
User context and permissions
Performance metrics
Error details and stack traces
Business Event Logging
Expense creation, updates, and deletions
Category management operations
Permission validation events
Financial data access and modifications
Performance Monitoring
Response time tracking for all endpoints
Database query performance analysis
Cache hit rates and effectiveness
Error rate monitoring and alerting
Security Considerations
Input Validation
Comprehensive validation of all financial data
Amount validation to prevent negative or invalid values
Date validation and format checking
Source and category reference validation
Access Control
Role-based permission system with granular controls
Tenant-based data isolation for multi-tenant security
API rate limiting and abuse prevention
Audit logging for all financial operations
Financial Data Protection
Encryption of sensitive financial information
Secure handling of currency and amount data
Compliance with financial data protection regulations
Regular security audits and vulnerability assessments
Integration Examples
Creating a Comprehensive Expense
Advanced Expense Search
Bulk Category Creation
Last updated
Was this helpful?