# POST /reports/count

**Resource:** [Reports](./reports.md)  
**MCP tool:** `count_records`  
**Scopes:** _none_  
**Write operation:** no

Count records and add up numbers across a WHOLE list in one call: how many, how much, and optionally split by one field. Use it for every "how many" or "what is the total" question: open pipeline value, won this month, invoiced or unpaid this month, overdue tasks, new leads by source. Never add up a page from a list_* tool instead: lists return one page, so that total is wrong. Free read. Same engine and numbers as the reporting screens. Opportunities (source "deals") leave out archived ones and pipelines excluded from lead reporting unless you include them.

## Parameters

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `source` | body | string | yes | What to count: "deals" (opportunities), "tasks", "invoices", "activities", "bookings", "stage_changes" (card moves), "referrals", "work_orders", "emails" or "calculator_results" (the latest calculator run on each opportunity; sum or filter its results as cf_<result key>, e.g. cf_lvr). list_report_sources lists every source and its fields. |
| `filters` | body | array | no | Optional; every filter must match. Each is { "field", "operator", "value" } with operator eq, neq, gt, gte, lt, lte, contains, like, is_null or is_not_null, or { "field", "operator": "in" or "not_in", "values": [...] }. Examples: open opportunities { "field": "status", "operator": "eq", "value": "open" } (status is open, won or lost); overdue tasks { "field": "is_overdue", "operator": "eq", "value": true }; unpaid invoices { "field": "payment_status", "operator": "eq", "value": "unpaid" } (paid, unpaid, draft or void). |
| `sum` | body | array | no | Number fields to add up. Opportunities: "value". Invoices: "total" (amount invoiced), "amount_due" (still owed), "amount_paid". |
| `group_by` | body | string | no | Split the answer by one field, for example "lead_source", "stage_name", "pipeline_name", "assigned_user_name", "assignee_name" or "status". Up to 50 groups, biggest first. The overall count and totals are always for the whole list. |
| `per` | body | string | no | Split the answer over time instead: one row per day, week, month, quarter or year on date_field, oldest first, every period present (empty ones are 0), each with a ready axis label. Use it for trends and charts ("invoiced per month this year", "new leads per week"). With no period or dates it covers the last 30 days (day), 12 weeks, 12 months, 8 quarters or 5 years. Not with group_by. |
| `period` | body | string | no | A calendar window on date_field, in the workspace timezone. Weeks start on Monday; last_7_days includes today. |
| `date_field` | body | string | no | The date the period or date range applies to. Defaults: opportunities deal_created_at (use won_at for "won this month", lost_at for lost), tasks due_date, invoices issue_date, activities activity_created_at, bookings starts_at, stage_changes moved_at, calculator_results run_at. |
| `date_from` | body | string | no | First day, YYYY-MM-DD, inclusive. Use instead of period for a custom range. |
| `date_to` | body | string | no | Last day, YYYY-MM-DD, inclusive. |
| `include_archived` | body | boolean | no | Opportunities only: count archived ones too (off by default). |
| `include_excluded_pipelines` | body | boolean | no | Opportunities only: include pipelines flagged as not for lead reporting (off by default). |

## Request example

```bash
curl -X POST   "https://api.trustpager.com/functions/v1/api/v1/reports/count"   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"source":"...","filters":"...","sum":"..."}'
```

---
Base URL: `https://api.trustpager.com/functions/v1/api/v1` — Auth: `Authorization: Bearer YOUR_API_KEY`