Overview
The Categories API allows users to create, read, update, and delete custom transaction categories. Categories are used to organize and classify income and expenses for better financial tracking.Categories are user-specific. Each user can create their own set of categories that work best for their financial tracking needs.
Authentication
All endpoints require session-based authentication via the@api_login_required decorator.
Get All Categories
Retrieve all categories for the authenticated user. Endpoint:GET /api/categories
Response
Returns an array of category objects.Response Fields
Unique 8-character category ID
Category name (e.g., “Groceries”, “Transportation”)
Category type:
"chi" (expense) or "thu" (income)Example Request
Create Category
Create a new transaction category. Endpoint:POST /api/categories
Request Body
The name of the category (e.g., “Dining Out”, “Freelance Income”)
Category type:
"chi" (expense) or "thu" (income)Example Request
Response
Error Response
Update Category
Update an existing category’s name or type. Endpoint:PUT /api/categories/{cat_id}
Path Parameters
The unique category ID
Request Body
Updated category name
Updated category type:
"chi" or "thu"Example Request
Response
Delete Category
Delete a category. Endpoint:DELETE /api/categories/{cat_id}
Path Parameters
The unique category ID to delete
Example Request
Response
Implementation Reference
The Categories API is implemented inapp/routes/foundation.py:
foundation.py
Database Schema
Categories are stored in thedanhmuc table with the following structure:
models.py
Related Endpoints
- Transactions API - Use categories when creating transactions
- AI Services API - AI predicts categories for transaction descriptions
- Reports API - Filter and analyze spending by category
