Skip to main content

POST /api/accrued-expenses

Creates a new manual expense entry for a specific profile and period. This endpoint is used for expenses that are not imported from XML files.

Authentication

This endpoint requires authentication. Include your access token in the request cookies.

Request Body

profile_id
string
required
ID of the profile (RFC emisor) to associate this expense with
period_id
string
required
ID of the accounting period for this expense
concept
string
required
Description or concept of the expense
subtotal
number
required
Subtotal amount before taxes
iva_amount
number
IVA (VAT) amount. If not provided, defaults to 0
fecha
string
required
Date of the expense in ISO 8601 format (e.g., “2024-03-15”)
type
string
required
Type of expense. Must be manual
categoria
string
Category for organizing the expense

Response

message
string
required
Success message
data
Expense
required
The created expense object

Example Request

curl -X POST "https://api.contafy.com/api/accrued-expenses" \
  -H "Content-Type: application/json" \
  -H "Cookie: access_token=your_access_token" \
  -d '{
    "profile_id": "profile-123",
    "period_id": "period-456",
    "concept": "Compra de papelería",
    "subtotal": 1000,
    "iva_amount": 160,
    "fecha": "2024-03-15",
    "type": "manual",
    "categoria": "Gastos de oficina"
  }'

Example Response

{
  "message": "Expense created successfully",
  "data": {
    "id": "expense-789",
    "profile_id": "profile-123",
    "tipo_origen": "MANUAL",
    "fecha": "2024-03-15T00:00:00Z",
    "mes": 3,
    "año": 2024,
    "total": 1160,
    "subtotal": 1000,
    "iva": 16,
    "iva_amount": 160,
    "concepto": "Compra de papelería",
    "categoria": "Gastos de oficina",
    "created_at": "2024-03-15T10:30:00Z",
    "updated_at": "2024-03-15T10:30:00Z"
  }
}

Error Responses

401 Unauthorized
error
Authentication required or token expired
{
  "error": "Unauthorized",
  "message": "Authentication required"
}
400 Bad Request
error
Invalid request body or missing required fields
{
  "error": "Bad Request",
  "message": "Missing required field: concept"
}
403 Forbidden
error
User does not have permission to create expenses for this profile
{
  "error": "Forbidden",
  "message": "You do not have permission to access this profile"
}
500 Internal Server Error
error
Server error occurred
{
  "error": "Internal Server Error",
  "message": "An unexpected error occurred"
}