> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getprimo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Count devices for up to 20 filters in one call

> Return only numbers: `{"counts":{"<label>":<number>}}`, one per labelled query. Use it for any how-many question about devices, one total or a breakdown (by MDM status, platform, availability, encryption, online state, custom field…) with one query per bucket, instead of calling `getDevices` once per bucket. A query takes the `filter`, `matchAny` and `search` of `getDevices`, keyed by the `key`s of `getDeviceFilterCatalog`, and counts what `getDevices` would return for it (`pagination.totalElements`): retired devices are left out unless the query has an `availableStatus` clause (INCLUDE keeps only the statuses it lists, EXCLUDE every other status, retired ones included), so the empty query `{}` counts every device not retired. An unknown criterion in any query rejects the whole call with 400, naming the label and the key. To list the devices behind a count, use `getDevices`. For the company headline KPIs (devices in use and in stock, MDM on or off, encryption, online) in one read, use `getCompanyMetrics`.

<span className="badge-read">Key: Read</span><span className="badge-company">Scope: Company</span>


## OpenAPI

````yaml https://api.getprimo.com/openapi.json post /devices/count
openapi: 3.1.1
info:
  title: Public API - BETA
  description: Read docs on https://docs.getprimo.com/
  version: '1.0'
  contact: {}
servers:
  - url: https://api.getprimo.com
security:
  - apikey: []
tags: []
paths:
  /devices/count:
    post:
      tags:
        - Devices
      summary: Count devices for up to 20 filters in one call
      description: >-
        Return only numbers: `{"counts":{"<label>":<number>}}`, one per labelled
        query. Use it for any how-many question about devices, one total or a
        breakdown (by MDM status, platform, availability, encryption, online
        state, custom field…) with one query per bucket, instead of calling
        `getDevices` once per bucket. A query takes the `filter`, `matchAny` and
        `search` of `getDevices`, keyed by the `key`s of
        `getDeviceFilterCatalog`, and counts what `getDevices` would return for
        it (`pagination.totalElements`): retired devices are left out unless the
        query has an `availableStatus` clause (INCLUDE keeps only the statuses
        it lists, EXCLUDE every other status, retired ones included), so the
        empty query `{}` counts every device not retired. An unknown criterion
        in any query rejects the whole call with 400, naming the label and the
        key. To list the devices behind a count, use `getDevices`. For the
        company headline KPIs (devices in use and in stock, MDM on or off,
        encryption, online) in one read, use `getCompanyMetrics`.
      operationId: countDevices
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CountDevicesBody'
      responses:
        default:
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CountDevices_Output'
components:
  schemas:
    CountDevicesBody:
      type: object
      properties:
        queries:
          description: >-
            Up to 20 device queries, each under a label you choose (letters,
            digits, "_" or "-"), e.g.
            `{"mdmOff":{"filter":{"mdmStatus":{"operationType":"INCLUDE","values":["MDM_OFF"]}}},"all":{}}`.
            A query takes the `filter`, `matchAny` and `search` of `getDevices`,
            nothing else.
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: object
            properties:
              filter:
                description: >-
                  One entry per criterion, keyed by the `key` returned by the
                  filter catalog (`GET /devices/filters-options`) — a native key
                  such as `platform`, `availableStatus`, `assigned` or
                  `mdmStatuses.online`, or a custom field id. Every value is a
                  clause { operationType, values } — never a bare value, never
                  an operator like `eq`. `availableStatus` takes only IN_USE,
                  IN_STOCK, RETIRED. Whether a device has an owner is `assigned`
                  (true or false), never a status. Enrollment is `mdmStatus`:
                  MDM_ON is enrolled, MDM_OFF, MISSING_AGENT, READY_ZTD and
                  MDM_ON_IN_ANOTHER_MDM are the other states. A device name or
                  serial number goes in `search`. The device type is not a
                  criterion: read `type` on the returned devices. An unknown key
                  is rejected with 400 rather than ignored. Illustrative
                  filters: devices free to hand out →
                  `{"availableStatus":{"operationType":"INCLUDE","values":["IN_STOCK"]},"assigned":{"operationType":"INCLUDE","values":[false]}}`;
                  devices offline for a week or more →
                  `{"mdmStatuses.online":{"operationType":"INCLUDE","values":["INACTIVE"]}}`;
                  macOS in use →
                  `{"platform":{"operationType":"INCLUDE","values":["MACOS"]},"availableStatus":{"operationType":"INCLUDE","values":["IN_USE"]}}`;
                  a custom field value →
                  `{"<customFieldId>":{"operationType":"INCLUDE","values":["<optionId>"]}}`.
                type: object
                propertyNames:
                  type: string
                additionalProperties:
                  type: object
                  properties:
                    operationType:
                      description: >-
                        INCLUDE keeps the devices matching the values, EXCLUDE
                        keeps the devices that do not.
                      type: string
                      enum:
                        - INCLUDE
                        - EXCLUDE
                    values:
                      description: >-
                        Values to match, always as an array — take them from the
                        criterion `values` in the filter catalog. Booleans are
                        accepted for flag criteria.
                      minItems: 1
                      type: array
                      items:
                        anyOf:
                          - type: string
                          - type: boolean
                  required:
                    - operationType
                    - values
              matchAny:
                description: >-
                  When true, a device matching ANY clause is returned (OR).
                  Omitted or false means every clause must match (AND).
                type: boolean
              search:
                description: >-
                  Free-text search over device name, serial number, owner and
                  custom field values.
                type: string
            additionalProperties: false
      required:
        - queries
    CountDevices_Output:
      type: object
      properties:
        counts:
          type: object
          description: >-
            The number of records matching each query, under the label the query
            was sent with
          propertyNames:
            type: string
          additionalProperties:
            type: integer
            minimum: 0
            maximum: 9007199254740991
      required:
        - counts
      additionalProperties: false
  securitySchemes:
    apikey:
      scheme: bearer
      bearerFormat: API key
      type: http
      description: >-
        Use your Primo API key in the Authorization header as `Bearer
        <API_KEY>`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.