# pub.techne.draft.query.countRecords

> How many records a pub.techne.draft.query names: the records listRecords would answer for it (the same read path, the platform's `decide` on every record answered as written or permissioned, and a curated `location` `in`/`covers` match settled again over the locations the curated view trusts), each once, so the count is what paging the list to its end would answer. The count stops at 1000 (`capped`). The query's `order`, `limit` and `signals` are ignored, so a record without the role a list is ordered by is still counted. Anyone may call it, signed in or not; an anonymous caller counts public records only. Draft tier.

- Kind: query
- Authority: query.draft.techne.pub
- Lexicon: 1
- Published by [lexicons.techne.town](https://lexicon.garden/identity/did:plc:cbtfheqpi4g6vlrha4tpoh53), the NSID's authority

## Links

- [Documentation](https://lexicon.garden/lexicon/did:plc:cbtfheqpi4g6vlrha4tpoh53/pub.techne.draft.query.countRecords)
- [Schema JSON](https://lexicon.garden/lexicon/did:plc:cbtfheqpi4g6vlrha4tpoh53/pub.techne.draft.query.countRecords/schema.json)
- [Analytics](https://lexicon.garden/lexicon/did:plc:cbtfheqpi4g6vlrha4tpoh53/pub.techne.draft.query.countRecords/analytics)

## Query (`pub.techne.draft.query.countRecords`)

Type: query · GET

### Parameters (query string)

- `groupBy` (string): Count per type or per author instead of in all.
  - Constraints: knownValues: type | author
- `params` (string): The query's parameters as a JSON object of strings (or lists of strings), e.g. {"here": "40.01,-105.27"}. `$viewer` and `$now` are the platform's and cannot be passed.
  - Constraints: maxLength: 8192
- `query` (string): A pub.techne.draft.query object, as JSON. Give this or `queryUri`.
  - Constraints: maxLength: 16384
- `queryUri` (string · at-uri): A published pub.techne.draft.query record to run. Give this or `query`.

### Output (application/json)

- `capped` (boolean, required): True when the count stopped at 1000.
- `count` (integer, required): Records counted (at most 1000).
- `groups` (array): With groupBy: the count per key, largest first.
  - `items` (ref)
    - Reference: `#group`
- `notServedHere` (ref): Present when a `near` or `covers` point or an `in` area of the query lies outside this operator's coverage, or an `in` area is not held here. The records answered are what this operator holds, not the whole answer: an empty list (or a zero count) with this set means "not served here", not "nothing there". Ask an operator that serves the place.
  - Reference: `pub.techne.draft.query.listRecords#notServedHere`

### Errors

- `InvalidRequest`: HTTP 400. A malformed or refused query or parameter.
- `ViewRequired`: HTTP 400. A branch of the query names no `view` (curated or asWritten): there is no default. The message names the branch.
- `NotCurated`: HTTP 400. A branch read with view `curated` names a type (`type is`/`type in`) no curator the commons root trusts covers; the message names the type. Read it with view `asWritten`.
- `NotFound`: HTTP 404. `queryUri` names no query record the caller may read.

## #group (`pub.techne.draft.query.countRecords#group`)

Type: object

### Properties

- `count` (integer, required)
- `key` (string, required)

## Schema

```json
{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "group": {
      "properties": {
        "count": {
          "type": "integer"
        },
        "key": {
          "type": "string"
        }
      },
      "required": [
        "key",
        "count"
      ],
      "type": "object"
    },
    "main": {
      "description": "How many records a pub.techne.draft.query names: the records listRecords would answer for it (the same read path, the platform's `decide` on every record answered as written or permissioned, and a curated `location` `in`/`covers` match settled again over the locations the curated view trusts), each once, so the count is what paging the list to its end would answer. The count stops at 1000 (`capped`). The query's `order`, `limit` and `signals` are ignored, so a record without the role a list is ordered by is still counted. Anyone may call it, signed in or not; an anonymous caller counts public records only. Draft tier.",
      "errors": [
        {
          "description": "HTTP 400. A malformed or refused query or parameter.",
          "name": "InvalidRequest"
        },
        {
          "description": "HTTP 400. A branch of the query names no `view` (curated or asWritten): there is no default. The message names the branch.",
          "name": "ViewRequired"
        },
        {
          "description": "HTTP 400. A branch read with view `curated` names a type (`type is`/`type in`) no curator the commons root trusts covers; the message names the type. Read it with view `asWritten`.",
          "name": "NotCurated"
        },
        {
          "description": "HTTP 404. `queryUri` names no query record the caller may read.",
          "name": "NotFound"
        }
      ],
      "output": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "capped": {
              "description": "True when the count stopped at 1000.",
              "type": "boolean"
            },
            "count": {
              "description": "Records counted (at most 1000).",
              "type": "integer"
            },
            "groups": {
              "description": "With groupBy: the count per key, largest first.",
              "items": {
                "ref": "#group",
                "type": "ref"
              },
              "type": "array"
            },
            "notServedHere": {
              "description": "Present when a `near` or `covers` point or an `in` area of the query lies outside this operator's coverage, or an `in` area is not held here. The records answered are what this operator holds, not the whole answer: an empty list (or a zero count) with this set means \"not served here\", not \"nothing there\". Ask an operator that serves the place.",
              "ref": "pub.techne.draft.query.listRecords#notServedHere",
              "type": "ref"
            }
          },
          "required": [
            "count",
            "capped"
          ],
          "type": "object"
        }
      },
      "parameters": {
        "properties": {
          "groupBy": {
            "description": "Count per type or per author instead of in all.",
            "knownValues": [
              "type",
              "author"
            ],
            "type": "string"
          },
          "params": {
            "description": "The query's parameters as a JSON object of strings (or lists of strings), e.g. {\"here\": \"40.01,-105.27\"}. `$viewer` and `$now` are the platform's and cannot be passed.",
            "maxLength": 8192,
            "type": "string"
          },
          "query": {
            "description": "A pub.techne.draft.query object, as JSON. Give this or `queryUri`.",
            "maxLength": 16384,
            "type": "string"
          },
          "queryUri": {
            "description": "A published pub.techne.draft.query record to run. Give this or `query`.",
            "format": "at-uri",
            "type": "string"
          }
        },
        "type": "params"
      },
      "type": "query"
    }
  },
  "id": "pub.techne.draft.query.countRecords",
  "lexicon": 1
}
```
