πΈ POST /withdraw
Withdraws funds from a userβs account. Requires a valid JWT token and a UUID identifying the account. Updates balances and persists changes securely.
π Summary
- Method:
POST
- URL:
/withdraw
- Auth: Required
- Tag:
accounts
π Headers
Authorization: Bearer <your-token>
Content-Type: application/json
π€ Request Parameters
Name | Type | Required | Description |
---|---|---|---|
uuid |
string | β | UUID of the account to withdraw from |
amount |
float | β | Amount to withdraw |
channel |
string | β | Withdrawal channel (e.g., mpesa, bank) |
transaction_number |
string | β | Optional reference number |
by |
string | β | Who initiated the withdrawal (default = βUserβ) |
date |
string | β | Timestamp of withdrawal (default = now) |
π₯ Example Request Body
{
"uuid": "acc-2023-savings-abc123",
"amount": 1000,
"channel": "bank",
"transaction_number": "BANK54321",
"by": "User"
}
β Success Response
{
"success": true,
"status": 200,
"account_uuid": "acc-2023-savings-abc123",
"balance": 2300,
"start_time": "2025-07-10T09:30:00.123Z",
"end_time": "2025-07-10T09:30:00.180Z",
"execution_time": 0.057
}
β Failure Responses
Status | Reason |
---|---|
400 |
Invalid withdrawal amount |
403 |
Not authorized for this account |
404 |
Account not found |
500 |
Server error / internal failure |
π§ Notes
- Withdrawals use
with_account_lock()
to ensure safe concurrency. - Errors are structured with timestamps for traceability.
- You must have sufficient permissions for the account.
π Sponsors
Support my work through GitHub Sponsors!