# Reports

> Read the agency's reports through the Fondaro API and MCP: list the metrics, then read any one as a table, as figures or as a list of changes.

Reports are the numbers behind the Reports screen, and lists of what changed on your leads and deals. Two routes read them: one lists the metrics, one reads a metric as a table. Both need the `crm:read` scope, and no role. The same two reads are the `list_report_metrics` and `run_report_metric` tools on [Fondaro MCP](https://www.fondaro.com/docs/api/mcp.md).

A metric you can read tomorrow appears in the list without a change to how you call: you list the metrics and run an id.

## Who sees which numbers

A key acts as the person it belongs to, with their role as it is now.

- A **member's** key reads the numbers of the leads and deals assigned to them. Sending `people` is refused with `403`, and so is an admin-only metric (team, commission, ads and social numbers).
- An **admin's** key reads the whole agency, unassigned leads included. Send `people` (comma-separated team member ids) to read only those people.

A metric about the agency itself, such as ads or social, takes no `people`: asking for one is a `400`.

## List the metrics

`GET /v1/reports/metrics`

| Parameter | Type | Required | Description |
|---|---|---|---|
| `category` | Query, string | No | Only one category: `leads`, `deals`, `tasks`, `calls`, `emails`, `team`, `ads` or `social` |

```bash
curl "https://api.fondaro.com/v1/reports/metrics?category=leads" \
  -H "Authorization: Bearer $FONDARO_API_KEY"
```

```json
{
  "data": [
    {
      "id": "leads.by_source",
      "kind": "numbers",
      "category": "leads",
      "label": "Leads by source",
      "description": "Distribution of leads across acquisition sources.",
      "groupBy": [{ "id": "source", "label": "Source" }],
      "filters": [{ "id": "tag", "label": "Tag", "kind": "tag" }],
      "takesPeople": true
    }
  ]
}
```

`kind` is `numbers` (figures by period, category or person) or `changes` (one row per change). `groupBy` and `filters` are what the metric takes, and `takesPeople` is `false` for the agency's own numbers. A filter's `kind` says what it takes: `tag` and `enum` a list of values, `id` one record's id and `boolean` `true`. A member's list leaves out the admin-only metrics.

## Read a metric

`GET /v1/reports/metrics/{metricId}`

| Parameter | Type | Required | Description |
|---|---|---|---|
| `metricId` | Path, string | Yes | An id from the list. It contains a dot, as in `leads.by_source` |
| `timeframe` | Query, string | No | `last_7d`, `last_30d` (the default), `last_90d`, `this_month`, `last_month`, `this_quarter`, `last_quarter`, `ytd` or `custom` |
| `from`, `to` | Query, date | With `custom` | The first and the last day, `YYYY-MM-DD`. `from` and `to` alone mean `custom` |
| `bucket` | Query, string | No | The period of a row in a series: `day`, `week` (the default), `month` or `quarter` |
| `groupBy` | Query, string | No | One of the metric's `groupBy` ids |
| `filters` | Query, JSON | No | The metric's filters as a JSON object of filter id to value: `{"source":["idealista"]}` |
| `people` | Query, string | No | Admins only: team member ids, comma-separated |
| `limit` | Query, integer | No | A list of changes only: rows a page. 100 by default, 500 at most |
| `cursor` | Query, string | No | A list of changes only: `nextCursor` from the page before |

A window is at most 731 days, and at most 366 with `bucket=day`.

### The table

Every metric answers the same table:

```json
{
  "metric": "leads.by_source",
  "label": "Leads by source",
  "kind": "numbers",
  "shape": "category",
  "from": "2026-10-21T00:00:00.000Z",
  "to": "2026-11-20T00:00:00.000Z",
  "people": "agency",
  "columns": [
    { "key": "category", "label": "Category", "type": "string" },
    { "key": "value", "label": "Leads", "type": "number" }
  ],
  "rows": [
    { "category": "idealista", "value": 41 },
    { "category": "Website", "value": 17 }
  ],
  "hasMore": false,
  "nextCursor": null,
  "value": { "value": 58 }
}
```

- `from` is included and `to` is not. `people` is `agency`, or the member ids the numbers are for.
- `columns` says what each key in a row is. `type` is `string`, `number`, `date`, `datetime`, `money`, `percent`, `id`, `people` (a list of `{ id, name }`) or `tags` (a list of `{ id, name }`).
- A **numbers** metric is one row per period (a series over time), per category, or per person (a leaderboard), or one row for a single number. `value` is the headline figure, with `previous` and `changePct` when the metric sets it against the window before. A numbers table is not paged: `hasMore` is `false`.
- A **changes** metric is one row per change, newest first, paged with `limit` and `cursor`.

```bash
curl "https://api.fondaro.com/v1/reports/metrics/leads.by_source?timeframe=last_30d" \
  -H "Authorization: Bearer $FONDARO_API_KEY"
```

### A list of changes

`leads.tag_changes` lists every time a lead's tags changed: what was added, what was taken off, the tags before and after, who changed them and where. Tag names are as they were at the time.

Tag changes are recorded from the day this list was switched on. Changes before that day were not recorded, so a window that starts earlier has nothing from before it.

```bash
curl -G "https://api.fondaro.com/v1/reports/metrics/leads.tag_changes" \
  --data-urlencode "timeframe=last_7d" \
  --data-urlencode "limit=2" \
  -H "Authorization: Bearer $FONDARO_API_KEY"
```

```json
{
  "metric": "leads.tag_changes",
  "label": "Lead tag changes",
  "kind": "changes",
  "from": "2026-11-13T00:00:00.000Z",
  "to": "2026-11-20T00:00:00.000Z",
  "people": "agency",
  "columns": [
    { "key": "at", "label": "When", "type": "datetime" },
    { "key": "leadId", "label": "Lead", "type": "id" },
    { "key": "leadName", "label": "Lead name", "type": "string" },
    { "key": "added", "label": "Added", "type": "tags" },
    { "key": "removed", "label": "Removed", "type": "tags" },
    { "key": "tagsBefore", "label": "Tags before", "type": "tags" },
    { "key": "tagsAfter", "label": "Tags after", "type": "tags" },
    { "key": "by", "label": "Changed by", "type": "id" },
    { "key": "byName", "label": "Changed by (name)", "type": "string" },
    { "key": "source", "label": "Where it was changed", "type": "string" }
  ],
  "rows": [
    {
      "at": "2026-11-19T16:02:11.000Z",
      "leadId": 1042,
      "leadName": "Maria Ortega",
      "added": [{ "id": "8a4e6d21-c3b9-4f70-a512-7e9d0c1b3a64", "name": "Viewing booked" }],
      "removed": [],
      "tagsBefore": [{ "id": "3f1c2a9e-5b7d-4e2a-9c61-0d8e4b7a2f10", "name": "Buyer" }],
      "tagsAfter": [{ "id": "3f1c2a9e-5b7d-4e2a-9c61-0d8e4b7a2f10", "name": "Buyer" }, { "id": "8a4e6d21-c3b9-4f70-a512-7e9d0c1b3a64", "name": "Viewing booked" }],
      "by": "user_2abc...",
      "byName": "Ana Costa",
      "source": "user"
    }
  ],
  "hasMore": true,
  "nextCursor": "eyJhdCI6..."
}
```

Send `nextCursor` back as `cursor`, with the same other parameters, for the next page. A change that no person made, such as an import, has the place it came from in `source`.

Filters narrow a list: `filters={"leadId":"1042"}` reads one lead's changes, and `filters={"tag":["8a4e6d21-c3b9-4f70-a512-7e9d0c1b3a64"]}` the changes that added or took off that tag.

## Metrics

The ids you can run. The list route is the source of truth for your key: a member's list leaves out the admin-only ones, and a metric appears there once it can be read.

| Category | Metric ids |
|---|---|
| Leads | `leads.created_over_time`, `leads.by_status`, `leads.by_source`, `leads.by_language`, `leads.by_country`, `leads.qualification_rate`, `leads.status_funnel`, `leads.avg_time_in_status`, `leads.purchased_revenue`, `leads.by_tag`, `leads.time_to_first_answer` |
| Deals | `deals.created_over_time`, `deals.pipeline_by_stage`, `deals.pipeline_value_by_stage`, `deals.win_rate`, `deals.won_lost_over_time`, `deals.revenue_won_over_time`, `deals.avg_deal_size`, `deals.avg_time_to_close`, `deals.lost_reasons`, `deals.avg_time_in_stage`, `deals.stalled`, `deals.commission_won_over_time`, `deals.commission_breakdown`, `deals.commission_by_agent` and `deals.commission_due_by_agent` (admin only) |
| Tasks | `tasks.completed_over_time`, `tasks.completion_rate`, `tasks.overdue`, `tasks.status_split` |
| Calls | `calls.over_time`, `calls.by_outcome`, `calls.answer_rate`, `calls.avg_duration`, `calls.cost_over_time`, `calls.sentiment`, `calls.top_objections` |
| Emails and messages | `emails.sent_over_time`, `emails.by_status`, `messages.by_channel` |
| Team | `team.leaderboard`, `team.activity_by_assignee`, `team.time_to_first_answer` (all admin only) |
| Ads | `ads.lead_outcomes`, `ads.spend_over_time`, `ads.spend`, `ads.leads`, `ads.cost_per_lead` (all admin only) |
| Social | `social.reach`, `social.engagement`, `social.followers` (all admin only) |
| Lists of changes | `leads.status_changes`, `deals.stage_changes`, `leads.assignment_changes`, `leads.tag_changes` |

## Errors

Errors have the [standard `/v1` envelope](https://www.fondaro.com/docs/api/errors-and-limits.md). The message says what is possible.

| Status | When |
|---|---|
| `400` | An unknown metric, a `groupBy` or a filter the metric does not take, `people` on an agency metric, a custom window without `from` and `to`, or a window past the limits |
| `401` | No valid API key |
| `403` | The key lacks `crm:read`, a member sent `people`, or a member asked for an admin-only metric |
| `500` | The metric could not be read on our side. Try again in a minute |

Source: https://www.fondaro.com/docs/api/v1/reports
