Skip to main content

Overview

The Bills API enables you to manage household bills, including tracking amounts, due dates, categories, and payment status. It also provides monthly bill aggregations.

Endpoints

Get All Bills

GET /api/bills
endpoint
Retrieves all bills for the authenticated user’s household, ordered by position.
Authentication: Required Response
bills
array
Array of bill objects
curl -X GET https://your-domain.com/api/bills \
  -H "Authorization: Bearer YOUR_CLERK_TOKEN"
Example Response
[
  {
    "id": "clx123abc",
    "householdId": "clx456def",
    "name": "Electric Bill",
    "amount": 125.50,
    "dueDate": "2024-03-25T00:00:00Z",
    "category": "Utilities",
    "position": 0,
    "checked": false,
    "createdAt": "2024-03-01T10:00:00Z",
  },
  {
    "id": "clx789ghi",
    "householdId": "clx456def",
    "name": "Internet",
    "amount": 79.99,
    "dueDate": "2024-03-15T00:00:00Z",
    "category": "Utilities",
    "position": 1,
    "checked": true,
    "createdAt": "2024-03-01T11:00:00Z",
  }
]

Create or Reorder Bills

POST /api/bills
endpoint
Creates a new bill or reorders existing bills.
Authentication: Required Request Body (Create) Request Body (Reorder)
curl -X POST https://your-domain.com/api/bills \
  -H "Authorization: Bearer YOUR_CLERK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Car Insurance",
    "amount": 250.00,
    "dueDate": "2024-04-01T00:00:00Z",
    "category": "Insurance"
  }'
Response (Create)
{
  "id": "clxnew123",
  "householdId": "clx456def",
  "name": "Car Insurance",
  "amount": 250.00,
  "dueDate": "2024-04-01T00:00:00Z",
  "category": "Insurance",
  "position": 2,
  "checked": false,
  "createdAt": "2024-03-15T12:00:00Z",
}
Response (Reorder)
Positions updated
Status: 200 OK

Update Bill

POST /api/bills/update
endpoint
Updates an existing bill’s details.
Authentication: Required Request Body
curl -X POST https://your-domain.com/api/bills/update \
  -H "Authorization: Bearer YOUR_CLERK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "clx123abc",
    "name": "Electric Bill",
    "amount": 135.75,
    "dueDate": "2024-03-28T00:00:00Z",
    "category": "Utilities"
  }'
Response
{
  "count": 1
}

Delete Bill

POST /api/bills/delete
endpoint
Deletes (marks as paid) a bill and creates a payment notification.
Authentication: Required Request Body
curl -X POST https://your-domain.com/api/bills/delete \
  -H "Authorization: Bearer YOUR_CLERK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"id": "clx123abc"}'
Response
{
  "id": "clx123abc",
  "householdId": "clx456def",
  "name": "Electric Bill",
  "amount": 125.50,
  "dueDate": "2024-03-25T00:00:00Z",
  "category": "Utilities",
  "position": 0,
  "checked": false,
  "createdAt": "2024-03-01T10:00:00Z",
}
When a bill is deleted, a notification is automatically created with:
  • Type: “bills”
  • Title: “Bill Paid”
  • Body: “You paid: [bill name] for $[amount]“

Get Bills Count

GET /api/bills/count
endpoint
Returns the total number of bills for the household.
Authentication: Required
curl -X GET https://your-domain.com/api/bills/count \
  -H "Authorization: Bearer YOUR_CLERK_TOKEN"
Response
{
  "count": 8
}

Get Monthly Bills Overview

GET /api/bills/monthly
endpoint
Returns aggregated bill data for 5 months (2 past, current, 2 future).
Authentication: Required Response
data
array
Array of monthly bill summaries
curl -X GET https://your-domain.com/api/bills/monthly \
  -H "Authorization: Bearer YOUR_CLERK_TOKEN"
Example Response
[
  {
    "month": "Jan",
    "total": 450.25,
    "paid": 450.25
  },
  {
    "month": "Feb",
    "total": 523.00,
    "paid": 523.00
  },
  {
    "month": "Mar",
    "total": 612.50,
    "paid": 205.50
  },
  {
    "month": "Apr",
    "total": 475.00,
    "paid": 0
  },
  {
    "month": "May",
    "total": 0,
    "paid": 0
  }
]
The monthly endpoint uses date-fns functions to calculate date ranges and aggregates bills based on their dueDate field. It considers a bill as “paid” if the checked field is true.

Error Responses

401 Unauthorized
User is not authenticated
Unauthorized
400 Bad Request
Missing required fields or invalid data
Missing fields
or
Missing or invalid ID
500 Internal Server Error
Unexpected server error
Internal Server Error

Source Code Reference

  • Main routes: ~/workspace/source/src/app/api/bills/route.ts:19
  • Count endpoint: ~/workspace/source/src/app/api/bills/count/route.ts:19
  • Delete endpoint: ~/workspace/source/src/app/api/bills/delete/route.ts:21
  • Update endpoint: ~/workspace/source/src/app/api/bills/update/route.ts:19
  • Monthly overview: ~/workspace/source/src/app/api/bills/monthly/route.ts:18

Build docs developers (and LLMs) love