Skip to main content

GET /api/transactions

Retrieves all transactions belonging to the authenticated user. Results are automatically ordered by creation date in descending order (most recent first).

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header:
Authorization: Bearer <your_token>

Request

This endpoint does not accept any query parameters or request body. It automatically filters transactions to show only those belonging to the authenticated user.

Example Request

curl -X GET http://localhost:3001/api/transactions \
  -H "Authorization: Bearer your_jwt_token"

Response

Returns an array of transaction objects. If the user has no transactions, an empty array is returned.
transactions
array
Array of transaction objects ordered by created_at in descending order.

Success Response Example

[
  {
    "id": 45,
    "user_id": 15,
    "transaction_type": "Comprar",
    "amount_usd": 100.00,
    "commission_usd": 7.40,
    "total_usd": 107.40,
    "rate_bs": 36.50,
    "total_bs": 3920.10,
    "payment_reference": "REF987654321",
    "status": "Completada",
    "type_pay": "Zelle",
    "recipient_account": "[email protected]",
    "created_at": "2026-03-04T10:30:00.000Z",
    "updated_at": "2026-03-04T11:00:00.000Z"
  },
  {
    "id": 42,
    "user_id": 15,
    "transaction_type": "Vender",
    "amount_usd": 50.00,
    "commission_usd": 3.40,
    "total_usd": 46.60,
    "rate_bs": 36.50,
    "total_bs": 1700.90,
    "payment_reference": "REF123456789",
    "status": "Pendiente",
    "type_pay": "Pago Móvil",
    "recipient_account": "0414-1234567",
    "created_at": "2026-03-03T14:20:00.000Z",
    "updated_at": "2026-03-03T14:20:00.000Z"
  },
  {
    "id": 38,
    "user_id": 15,
    "transaction_type": "Comprar",
    "amount_usd": 25.00,
    "commission_usd": 1.40,
    "total_usd": 26.40,
    "rate_bs": 36.20,
    "total_bs": 955.68,
    "payment_reference": "REF555111222",
    "status": "Completada",
    "type_pay": "Transferencia",
    "recipient_account": "0102-1234-5678-9012",
    "created_at": "2026-03-01T09:15:00.000Z",
    "updated_at": "2026-03-01T10:45:00.000Z"
  }
]

Empty Response Example

When the user has no transactions:
[]

Error Responses

401 Unauthorized
object
Returned when the authentication token is missing, invalid, or expired.
{
  "message": "Authentication required"
}
500 Internal Server Error
object
Returned when an unexpected server error occurs.
{
  "message": "Error del servidor"
}

Implementation Details

Filtering

The endpoint automatically filters transactions based on the authenticated user’s ID. Users can only see their own transactions and cannot access transactions belonging to other users. Database query:
SELECT * FROM transactions 
WHERE user_id = ? 
ORDER BY created_at DESC

Ordering

Results are always ordered by the created_at field in descending order, ensuring that the most recent transactions appear first in the response array.

Pagination

The current implementation returns all transactions for the user without pagination. For users with large transaction histories, consider implementing pagination in your client application or requesting a paginated version of this endpoint.

Use Cases

Transaction History Display

Use this endpoint to display a complete transaction history in your application:
curl -X GET http://localhost:3001/api/transactions \
  -H "Authorization: Bearer your_jwt_token"

Filtering Client-Side

Since all transactions are returned, you can filter by status, type, or date range on the client side:
// Example: Filter for pending transactions
const pendingTransactions = transactions.filter(
  tx => tx.status === 'Pendiente'
);

// Example: Filter for buy transactions
const buyTransactions = transactions.filter(
  tx => tx.transaction_type === 'Comprar'
);

// Example: Filter by date range
const recentTransactions = transactions.filter(
  tx => new Date(tx.created_at) > new Date('2026-03-01')
);

Calculating Statistics

Use the response data to calculate user statistics:
// Total USD transacted
const totalUSD = transactions.reduce(
  (sum, tx) => sum + tx.total_usd, 
  0
);

// Total commissions paid
const totalCommissions = transactions.reduce(
  (sum, tx) => sum + tx.commission_usd, 
  0
);

// Number of completed transactions
const completedCount = transactions.filter(
  tx => tx.status === 'Completada'
).length;

Build docs developers (and LLMs) love