---
source_url: https://www.pubnub.com/docs/admin-api/create-metric
title: Create metric
---

# Create metric

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

Creates a new metric for data aggregation. A metric defines an aggregation function applied to business object fields over a time window.

### measureId conditional requirement

| Function | `measureId` | Field type |
| --- | --- | --- |
| `COUNT`, `COUNT_DISTINCT` | **Omit** — these count occurrences, no field needed | N/A |
| `AVG`, `MAX`, `MIN`, `SUM` | **Required** — must reference a `NUMERIC` field from the Business Object | `jsonFieldType: "NUMERIC"` |

`dimensionIds` reference `TEXT` fields used for grouping (e.g., group by user or region). `filters[].sourceId` references a field from the Business Object.

> **Note:** The `filters[].id` field is auto-generated on create. Include it in subsequent PUT requests when updating filters.

### evaluationWindow allowed values

Only the following values (in seconds) are accepted — arbitrary values will be rejected:

| Value | Duration |
| --- | --- |
| `60` | 1 minute |
| `300` | 5 minutes |
| `600` | 10 minutes |
| `900` | 15 minutes |
| `1800` | 30 minutes |
| `3600` | 1 hour |
| `86400` | 1 day |

## Request

Example

```
{
  "id": "string",
  "name": "string",
  "measureId": "string",
  "businessObjectId": "string",
  "evaluationWindow": 0,
  "function": "string",
  "dimensionIds": [
    "string"
  ],
  "dimensions": [
    {
      "id": "string",
      "name": "string",
      "jsonPath": "string",
      "jsonFieldType": "TEXT",
      "isKeyset": false,
      "source": "JSONPATH",
      "derivation": {
        "operation": "TIME_DIFF",
        "params": {}
      }
    }
  ],
  "filters": [
    {
      "id": "string",
      "sourceType": "MEASURE",
      "sourceId": "string",
      "operation": "NUMERIC_GREATER_THAN",
      "arguments": [
        "string"
      ]
    }
  ],
  "businessObject": {
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:00:00.000Z",
    "createdBy": "string",
    "updatedBy": "string",
    "id": "string",
    "name": "string",
    "isActive": false,
    "description": "string",
    "fields": [
      {
        "id": "string",
        "name": "string",
        "jsonPath": "string",
        "jsonFieldType": "TEXT",
        "isKeyset": false,
        "source": "JSONPATH",
        "derivation": {}
      }
    ],
    "accountId": "string",
    "subkeys": [
      "string"
    ],
    "metrics": [],
    "decisions": [
      {
        "createdAt": "2024-01-01T00:00:00.000Z",
        "updatedAt": "2024-01-01T00:00:00.000Z",
        "createdBy": "string",
        "updatedBy": "string",
        "id": "string",
        "name": "string",
        "description": "string",
        "accountId": "string",
        "businessObjectId": "string",
        "sourceType": "BUSINESSOBJECT",
        "sourceId": "string",
        "hitType": "SINGLE",
        "enabled": false,
        "activeFrom": "2024-01-01T00:00:00.000Z",
        "activeUntil": "2024-01-01T00:00:00.000Z",
        "executeOnce": false,
        "executionFrequency": 0,
        "inputFields": [],
        "outputFields": [],
        "rules": [],
        "actions": [],
        "query": {},
        "customer": {}
      }
    ],
    "dashboards": [
      {
        "createdAt": "2024-01-01T00:00:00.000Z",
        "updatedAt": "2024-01-01T00:00:00.000Z",
        "createdBy": "string",
        "updatedBy": "string",
        "id": "string",
        "name": "string",
        "accountId": "string",
        "dateRange": "30 minutes",
        "startDate": "2024-01-01T00:00:00.000Z",
        "endDate": "2024-01-01T00:00:00.000Z",
        "charts": [],
        "customer": {}
      }
    ],
    "queries": [
      {
        "createdAt": "2024-01-01T00:00:00.000Z",
        "updatedAt": "2024-01-01T00:00:00.000Z",
        "createdBy": "string",
        "updatedBy": "string",
        "decisions": [],
        "customer": {},
        "businessObjects": [],
        "id": "string",
        "name": "string",
        "description": "string",
        "definition": {},
        "template": "string",
        "accountId": "string"
      }
    ],
    "customers": [
      {
        "id": "string",
        "name": "string"
      }
    ]
  }
}
```
