Skip to main content

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).
GET
method
/api/transactions

Authentication

Required. User must be logged in with valid session.

Response

transactions
array
Array of transaction objects

Example Request

curl -X GET https://api.finai.com/api/transactions \
  -H "Cookie: session=your-session-cookie"

Example Response

[
  {
    "id": "a3f7b29c",
    "type": "chi",
    "amount": 150000,
    "description": "Mua cà phê sáng",
    "date": "2024-03-15",
    "category_id": "c1234567",
    "category_name": "Ăn uống",
    "wallet_id": "w9876543",
    "wallet_name": "Tiền mặt",
    "dest_wallet_id": null,
    "dest_wallet_name": null
  },
  {
    "id": "b8e2d14a",
    "type": "thu",
    "amount": 5000000,
    "description": "Lương tháng 3",
    "date": "2024-03-01",
    "category_id": "c7654321",
    "category_name": "Lương",
    "wallet_id": "w1234567",
    "wallet_name": "Ngân hàng",
    "dest_wallet_id": null,
    "dest_wallet_name": null
  }
]

Create Transaction

Add a new transaction and automatically update wallet balances.
POST
method
/api/transactions

Request Body

type
string
required
Transaction type: expense, income, or transfer
amount
number
required
Transaction amount (must be positive)
description
string
Transaction description or note
date
string
Transaction date in YYYY-MM-DD format (defaults to current date)
category_id
string
Category ID to classify the transaction
source_wallet_id
string
required
Source wallet ID (for expenses and transfers)
dest_wallet_id
string
Destination wallet ID (required for transfers and income)
ai_category_id
string
AI-predicted category ID
ai_confidence
number
AI prediction confidence score (0-100)

Balance Updates

  • Subtracts amount from source wallet
  • Uses source_wallet_id as the primary wallet

Example Request

curl -X POST https://api.finai.com/api/transactions \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your-session-cookie" \
  -d '{
    "type": "expense",
    "amount": 250000,
    "description": "Đổ xăng xe",
    "date": "2024-03-15",
    "category_id": "c2468135",
    "source_wallet_id": "w9876543"
  }'

Response

status
string
success or error
message
string
Success or error message
Success
{
  "status": "success",
  "message": "Đã lưu giao dịch!"
}
Error - Missing Wallet
{
  "status": "error",
  "message": "Chưa chọn ví"
}

Error Codes

Status CodeDescription
200Transaction created successfully
400Missing required field (wallet)
401Unauthorized (not logged in)
500Database or validation error

Update Transaction

Modify an existing transaction. Automatically reverts old balance changes and applies new ones.
PUT
method
/api/transactions/:trans_id

Path Parameters

trans_id
string
required
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

  1. Reverts the original transaction’s wallet changes
  2. Updates transaction fields with new data
  3. Applies new wallet changes based on updated values

Example Request

curl -X PUT https://api.finai.com/api/transactions/a3f7b29c \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your-session-cookie" \
  -d '{
    "type": "expense",
    "amount": 300000,
    "description": "Đổ xăng xe - cập nhật",
    "date": "2024-03-15",
    "category_id": "c2468135",
    "source_wallet_id": "w9876543"
  }'

Response

Success
{
  "status": "success",
  "message": "Đã cập nhật!"
}
Error - Not Found
{
  "status": "error",
  "message": "Không tìm thấy"
}

Error Codes

Status CodeDescription
200Transaction updated successfully
401Unauthorized
404Transaction not found
500Database error

Delete Transaction

Remove a transaction and revert its wallet balance changes.
DELETE
method
/api/transactions/:trans_id

Path Parameters

trans_id
string
required
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

curl -X DELETE https://api.finai.com/api/transactions/a3f7b29c \
  -H "Cookie: session=your-session-cookie"

Response

Success
{
  "status": "success"
}
Error
{
  "status": "error",
  "message": "Transaction not found or deletion failed"
}

Error Codes

Status CodeDescription
200Transaction deleted successfully
401Unauthorized
404Transaction not found
500Database error

Implementation Reference

Source: app/routes/transaction.py

Build docs developers (and LLMs) love