Overview
The Transactions API allows you to create, read, update, and delete financial transactions. All endpoints require authentication via session cookies. Base Path:/api/transactions
Authentication: Required (@api_login_required decorator)
Get All Transactions
Retrieve all transactions for the authenticated user, ordered by date (most recent first)./api/transactions
Authentication
Required. User must be logged in with valid session.Response
Array of transaction objects
Example Request
Example Response
Create Transaction
Add a new transaction and automatically update wallet balances./api/transactions
Request Body
Transaction type:
expense, income, or transferTransaction amount (must be positive)
Transaction description or note
Transaction date in YYYY-MM-DD format (defaults to current date)
Category ID to classify the transaction
Source wallet ID (for expenses and transfers)
Destination wallet ID (required for transfers and income)
AI-predicted category ID
AI prediction confidence score (0-100)
Balance Updates
- Expense (chi)
- Income (thu)
- Transfer (chuyen)
- Subtracts amount from source wallet
- Uses
source_wallet_idas the primary wallet
Example Request
Response
success or errorSuccess or error message
Success
Error - Missing Wallet
Error Codes
| Status Code | Description |
|---|---|
| 200 | Transaction created successfully |
| 400 | Missing required field (wallet) |
| 401 | Unauthorized (not logged in) |
| 500 | Database or validation error |
Update Transaction
Modify an existing transaction. Automatically reverts old balance changes and applies new ones./api/transactions/:trans_id
Path Parameters
Transaction ID to update
Request Body
Same as Create Transaction endpoint. All fields from the original transaction should be included with updated values.Balance Adjustment Logic
- Reverts the original transaction’s wallet changes
- Updates transaction fields with new data
- Applies new wallet changes based on updated values
Example Request
Response
Success
Error - Not Found
Error Codes
| Status Code | Description |
|---|---|
| 200 | Transaction updated successfully |
| 401 | Unauthorized |
| 404 | Transaction not found |
| 500 | Database error |
Delete Transaction
Remove a transaction and revert its wallet balance changes./api/transactions/:trans_id
Path Parameters
Transaction ID to delete
Balance Reversion
- Expenses: Amount is added back to the source wallet
- Income: Amount is subtracted from the destination wallet
- Transfers: Amount is added back to source and subtracted from destination
Example Request
Response
Success
Error
Error Codes
| Status Code | Description |
|---|---|
| 200 | Transaction deleted successfully |
| 401 | Unauthorized |
| 404 | Transaction not found |
| 500 | Database error |
Implementation Reference
Source:app/routes/transaction.py
