> For the complete documentation index, see [llms.txt](https://docs.nexthink.com/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexthink.com/platform/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/api-and-integrations-classic/other-integrations-classic/count-metrics-api-classic.md).

# Count Metrics API (classic)

## Overview <a href="#countmetricsapi-classic-overview" id="countmetricsapi-classic-overview"></a>

Count metrics let you measure the number of objects that satisfy a particular set of conditions every day. To integrate data of count metrics with external systems, Portal provides an API to query the [details of count metrics](/platform/user-guide/custom-dashboards-classic/examining-metrics-in-depth-classic.md#examiningmetricsindepth-classic-displayingthedetailsofcountmetrics). The details of count metrics list the objects that took part in the count, along with any additional display fields that were selected for the metric.

The client of the *Count Metrics API* must trust the certificate in the primary Appliance (Portal).

To authenticate the client, the Count Metrics API uses Basic Authentication. Nexthink recommends creating a local account to exclusively authenticate clients of the API.

## Finding out available metrics <a href="#countmetricsapi-classic-findingoutavailablemetrics" id="countmetricsapi-classic-findingoutavailablemetrics"></a>

To interactively look for the details of count metrics that are available through the API:

1. Point a web browser to the following address:

   ```
   https://<Portal_DNS_FQDN>/api/metrics/v1​
   ```

   * Substitute `<Portal_DNS_FQDN>` for the actual name of Portal.
2. Log in to the discovery tool of the API as a user with the right to see count metrics (either because the user can see all metrics or because the metric is part of a module that is included in the roles of the user).
   * Type in the user credentials whenever asked by the web browser.
   * The discovery tool displays only the available metrics in the [view domain of the user](https://github.com/nexthink/documentation.online/blob/review/docs/Establishing-a-privacy-policy/README.md#limiting-the-view-to-a-domain_94994462.md).
   * Depending on the [data privacy settings of the user](https://github.com/nexthink/documentation.online/blob/review/docs/Establishing-a-privacy-policy/README.md#anonymization_94994462.md), the names and other identifying attributes of the objects in the details of the count metrics may be anonymized.
3. Select a metric from the table.
4. Select an available hierarchy.
5. Optional: Select a node (in the **Select Path** column) to restrict the output to a node of the hierarchy. Repeat for each level of the hierarchy.
6. Optional: To select particular time scope, click the link under the **Scopes** column. The choice of scope is also displayed when you navigate down the hierarchy and you reach the lowest level (the Entity level).
   1. Under **Select scope** choose among:
      * **day**
      * **week**
      * **month**
      * **quarter**
   2. Depending on the selected scope, choose the **Period**. To retrieve data from the past, ensure that you reserved enough disk space for the details of count metrics. Three options which demonstrate the three different ways of specifying a period are available:
      * **default period - last \<scope>**
      * **offset - three \<scopes> ago**
      * **specific \<scope>**
7. Click any of the links under the columns labeled **API link (\<format>)** to get the details of the count metric for the selected path, scope, and period. If you did not select any scope or period, the default values are applied (see table below in [querying the API](#countmetricsapi-classic-queryingtheapi)).
   * **table** (HTML table)
   * **json**
   * **csv**

Once you have reached the desired details of the metric, note down the URL built by the discovery tool to programmatically query the API later with the same request or use it as a base for your own requests.

## Querying the API <a href="#countmetricsapi-classic-queryingtheapi" id="countmetricsapi-classic-queryingtheapi"></a>

To query the Count metrics API, send a GET request to a URL that includes the following parameters:

| Parameter | Description                                                                                                                                                                                                                                                                                                                                                  | Default value                                                                                                                                        |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| metric    | UID of the desired metric                                                                                                                                                                                                                                                                                                                                    | (none)                                                                                                                                               |
| hierarchy | Name of a hierarchy                                                                                                                                                                                                                                                                                                                                          | The name of the first hierarchy in Portal                                                                                                            |
| scope     | <p>The</p><ul><li><strong>day</strong></li><li><strong>week</strong></li><li><strong>month</strong></li><li><strong>quarter</strong></li></ul>                                                                                                                                                                                                               | **day**                                                                                                                                              |
| period    | <p>The period depends on the scope defined.</p><ul><li><p>ISO 8601 compatible format:</p><ul><li>For day: 2017-10-22</li><li>For week: 2017-W22</li><li>For month: 2017-03</li><li>For quarter: 2017-Q1</li></ul></li><li><p>Relative expressions using <em>now</em>:</p><ul><li>If scope=day, <strong>now - 2</strong> is two days ago.</li></ul></li></ul> | <ul><li>If scope=day, yesterday</li><li>If scope=week, last week</li><li>If scope=month, last month</li><li>If scope=quarter, last quarter</li></ul> |
| path      | Name of a node in the hierarchy to limit the output. Chain several path elements to limit the output further down in the hierarchy levels.                                                                                                                                                                                                                   | The highest node in the view domain of the user                                                                                                      |
| format    | <p>Output format, one of:</p><ul><li><strong>table</strong> (for an HTML table)</li><li><strong>json</strong></li><li><strong>csv</strong></li></ul>                                                                                                                                                                                                         | **table**                                                                                                                                            |

Example of a query URL:

```
https://<Portal_DNS_FQDN>/api/metrics/v1/details?​
metric=7bfae274-6c0d-406f-8c02-d1932fdf6e89&​
hierarchy=DefaultHierarchy&​
path=Europe&path=Switzerland&path=Lausanne&​
scope=day&​
period=2019-08-22​&
format=table
```

\
The Count Metrics API uses Basic Authentication. To test the API from a Nexthink appliance, you can use `curl`, for instance:

```
curl https://<Portal_DNS_FQDN>/api/metrics/v1/details?... -u username:password
```

## Output of the Count Metrics API <a href="#countmetricsapi-classic-outputofthecountmetricsapi" id="countmetricsapi-classic-outputofthecountmetricsapi"></a>

The output of the API is similar to the [details of count metrics](/platform/user-guide/custom-dashboards-classic/examining-metrics-in-depth-classic.md#examiningmetricsindepth-classic-displayingthedetailsofcountmetrics) that you can explore in Portal.

Find below the complete list of outputs of the Count Metrics API:

| Output data     | Description                                                                                                                                                                                                                               |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Period          | <p>The value of the period selected as input. The column is labeled with the associated scope:</p><ul><li><strong>Date</strong></li><li><strong>Week</strong></li><li><strong>Month</strong></li><li><strong>Quarter</strong></li></ul>   |
| Hierarchy       | The name of the hierarchy selected as input parameter.                                                                                                                                                                                    |
| Hierarchy nodes | The chain of nodes specified as path parameters in the input, where each node is displayed on a separate column that has the label of the corresponding hierarchy level.                                                                  |
| Display fields  | The attributes of the objects that constitute the details of the count metric and specified as *display fields* in the definition of the metric. Each value is displayed in a separate column and labeled with the name of the attribute. |

***

RELATED TASKS

* [Creating a metric](/platform/user-guide/using-finder-classic/monitoring-it-custom-metrics-with-finder-classic/creating-a-metric-with-finder-classic.md)
* [Displaying the details of count metrics](/platform/user-guide/custom-dashboards-classic/examining-metrics-in-depth-classic.md#examiningmetricsindepth-classic-displayingthedetailsofcountmetrics)

RELATED REFERENCES

* [Establishing a privacy policy](https://github.com/nexthink/documentation.online/blob/review/docs/Establishing-a-privacy-policy_94994462.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nexthink.com/platform/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/api-and-integrations-classic/other-integrations-classic/count-metrics-api-classic.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
