# Statistics

> Count your listings per status, and count network listings per town, region, country and type for menus and pickers.

Two read-only counts: how many of your listings are in each status, and how listings spread across places and types, for location menus, filter dropdowns and place pickers. Both need the `properties:read` scope.

## Count your listings per status

### `GET /properties/stats/counts`

```bash
curl https://api.fondaro.com/properties/stats/counts \
  -H "Authorization: Bearer fondaro_pk_abc123"
```

```json
{
  "active": 48,
  "inactive": 12,
  "pending": 5,
  "sold": 23,
  "rented": 8
}
```

Every status is present, with `0` when you have none. Deleted listings are not counted.

## Count listings by place and type

### `GET /properties/stats/aggregations`

Counts every agency's active listings by default. Asking for your own listings, or for any status other than `active`, counts only your agency's.

| Query | Type | Meaning |
|---|---|---|
| `status` | string | Default `active`; any other status counts your own listings only |
| `filterByOrganization` | boolean | Count only your own listings |
| `countryCode`, `region`, `city` | string, repeatable | Narrow the counts (`countryCode=ES&countryCode=PT`) |
| `q` | string | Place-picker text: narrows towns and regions to names containing it (accents and case ignored) and adds matching `communities` |

```bash
curl "https://api.fondaro.com/properties/stats/aggregations?countryCode=ES" \
  -H "Authorization: Bearer fondaro_pk_abc123"
```

```json
{
  "byCity": {
    "Marbella": { "total": 45, "byType": { "house_detached": 12, "apartment": 28, "penthouse": 5 } },
    "Calpe": { "total": 18, "byType": { "apartment": 14, "townhouse": 4 } }
  },
  "byRegion": {
    "Costa del Sol": { "total": 45, "byType": { "house_detached": 12, "apartment": 28, "penthouse": 5 } }
  },
  "byCountry": {
    "ES": { "total": 63, "byType": { "house_detached": 12, "apartment": 42, "penthouse": 5, "townhouse": 4 } }
  },
  "byPropertyType": { "house_detached": 12, "apartment": 42, "penthouse": 5, "townhouse": 4 },
  "byPropertyCategory": { "residential": 63 },
  "availableCities": ["Marbella", "Calpe"],
  "availableRegions": ["Costa del Sol", "Costa Blanca"],
  "availableCountries": ["ES"],
  "availablePropertyTypes": ["house_detached", "apartment", "penthouse", "townhouse"],
  "availablePropertyCategories": ["residential"],
  "totalProperties": 63
}
```

Use the names in `availableCities` and `availableRegions` as the `city` and `region` filters of [Search](https://www.fondaro.com/docs/api/properties/search.md).

### Search places

With `q`, the response also has `communities`: areas whose name, town or region contains `q`, most listings first, up to 50. One community name can exist in two towns, so each carries its town.

```bash
curl "https://api.fondaro.com/properties/stats/aggregations?q=quinta" \
  -H "Authorization: Bearer fondaro_pk_abc123"
```

```json
{
  "communities": [
    { "name": "La Quinta", "city": "Benahavís", "region": "Málaga", "total": 7 }
  ]
}
```

## Freshness

Network-wide active counts are cached for 5 minutes, so a listing published a moment ago can take that long to appear. Counts of your own listings are always current.

Source: https://www.fondaro.com/docs/api/properties/stats
