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

# Manage metrics

<div className="m-badge-page-wrapper">
  <Badge stroke color="orange" size="sm">Limited Release</Badge>
</div>

Metric management helps you monitor, update, and delete existing metrics. You can retrieve metric configurations and modify metric settings to track different usage patterns and adjust billing calculations as your business requirements change.

## List metrics

Use a <a href="/developer/how-to/api/get-started#2-get-an-access-token" target="_blank" rel="noopener noreferrer">valid access token</a> and make a GET call to the `/v1/commerce/billing/metrics` endpoint. Include the following query parameters:

| <span style={{textAlign: 'left', display: 'block'}}>Parameter</span>                 | <span style={{textAlign: 'left', display: 'block'}}>Action</span>              |
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| `page`<br /><span style={{color: '#95a5a6', fontSize: 'smaller'}}>integer</span>     | Set the page number for paginated results. Default is `1`.                     |
| `per_page`<br /><span style={{color: '#95a5a6', fontSize: 'smaller'}}>integer</span> | Set the number of items to return per page. Default is `10`, maximum is `100`. |

<CodeGroup>
  ```shell lines title="Sample request" theme={null}
  curl -X GET 'https://api-m.sandbox.paypal.com/v1/commerce/billing/metrics?page=1&per_page=10' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <ACCESS-TOKEN>'
  ```

  ```json lines expandable title="Sample response" theme={null}
  {
    "metrics": [
      {
        "id": "bm_01H2XT1G7N8E2JHJKBVPDS0TQD",
        "name": "API Requests",
        "code": "api_requests",
        "type": "METERED",
        "description": "Measures the total number of API requests made",
        "aggregation_type": "COUNT",
        "field_filters": [
          {
            "key": "region",
            "values": [
              "us-east-1",
              "us-west-1",
              "eu-west-1"
            ]
          }
        ],
        "created_at": "2023-05-10T14:32:18Z"
      },
      {
        "id": "bm_01H2XT1G7N8E2JHJKBVPDS0TQE",
        "name": "Storage Usage",
        "code": "storage_usage",
        "type": "RECURRING",
        "description": "Tracks total storage consumption in GB",
        "aggregation_type": "SUM",
        "aggregation_field": "storage_gb",
        "created_at": "2023-05-10T14:35:22Z"
      }
    ],
    "pagination_metadata": {
      "total_count": 2,
      "total_pages": 1,
      "current_page": 1
    }
  }
  ```
</CodeGroup>

A successful call returns a `200 OK` response with a paginated list of all configured metrics.

## Update metric details

Use a <a href="/developer/how-to/api/get-started#2-get-an-access-token" target="_blank" rel="noopener noreferrer">valid access token</a> and make a PUT call to the `/v1/commerce/billing/metrics/{metric_code}` endpoint with the modified request parameters such as name, description, aggregation type, aggregation field, and field filters.

**Path parameter**: `metric_code` is the `code` you provided when you <a href="/limited-release/usage-based-billing/set-up-billing-process/create-metrics" target="_blank" rel="noopener noreferrer">created the metric</a>.

<Note>
  You cannot modify the metric code or type after creation. You can only update the name, description, aggregation type, aggregation field, and field filters.
</Note>

For information on all parameters, see <a href="/reference/api/rest/metrics/update-a-metric-by-code" target="_blank" rel="noopener noreferrer">API reference</a>.

<CodeGroup>
  ```shell lines title="Sample request" theme={null}
  curl -X PUT 'https://api-m.sandbox.paypal.com/v1/commerce/billing/metrics/api_requests' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <ACCESS-TOKEN>' \
  -d '{
    "name": "Updated API Requests",
    "description": "Measures the total number of API requests made across all regions",
    "aggregation_type": "COUNT",
    "field_filters": [
      {
        "key": "region",
        "values": [
          "us-east-1",
          "us-west-1",
          "eu-west-1",
          "ap-southeast-1"
        ]
      }
    ]
  }'
  ```

  ```json lines title="Sample response" theme={null}
  {
    "id": "bm_01H2XT1G7N8E2JHJKBVPDS0TQD",
    "name": "Updated API Requests",
    "code": "api_requests",
    "type": "METERED",
    "description": "Measures the total number of API requests made across all regions",
    "aggregation_type": "COUNT",
    "field_filters": [
      {
        "key": "region",
        "values": [
          "us-east-1",
          "us-west-1",
          "eu-west-1",
          "ap-southeast-1"
        ]
      }
    ],
    "created_at": "2023-05-10T14:32:18Z"
  }
  ```
</CodeGroup>

A successful call returns a `200 OK` response with the updated metric information.

## Delete metric

Use a <a href="/developer/how-to/api/get-started#2-get-an-access-token" target="_blank" rel="noopener noreferrer">valid access token</a> and make a DELETE call to the `/v1/commerce/billing/metrics/{metric_code}` endpoint to permanently delete a metric.

**Path parameter**: `metric_code` is the `code` you provided when you <a href="/limited-release/usage-based-billing/set-up-billing-process/create-metrics" target="_blank" rel="noopener noreferrer">created the metric</a>.

<Warning>
  Deleting a metric is permanent and affects all pricing plans and subscriptions using this metric. Ensure you remove the metric from all plans before deletion to avoid billing disruptions.
</Warning>

<CodeGroup>
  ```shell lines title="Sample request" theme={null}
  curl -X DELETE 'https://api-m.sandbox.paypal.com/v1/commerce/billing/metrics/api_requests' \
  -H 'Authorization: Bearer <ACCESS-TOKEN>'
  ```
</CodeGroup>

A successful call returns a `204 No Content` response.
