---
title: Update a derived metric
description: Update the definition of an existing derived metric.
breadcrumbs: Docs > API > Update a derived metric
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/llms.txt).

# Update a derived metric

## v2 (latest)

| Datadog site      | API endpoint                                                                   |
| ----------------- | ------------------------------------------------------------------------------ |
| app.datadoghq.com | PUT https://api.datadoghq.com/api/v2/metrics/derived-metrics/{metric_name}     |
| us3.datadoghq.com | PUT https://api.us3.datadoghq.com/api/v2/metrics/derived-metrics/{metric_name} |
| us5.datadoghq.com | PUT https://api.us5.datadoghq.com/api/v2/metrics/derived-metrics/{metric_name} |
| app.datadoghq.eu  | PUT https://api.datadoghq.eu/api/v2/metrics/derived-metrics/{metric_name}      |
| ap1.datadoghq.com | PUT https://api.ap1.datadoghq.com/api/v2/metrics/derived-metrics/{metric_name} |
| ap2.datadoghq.com | PUT https://api.ap2.datadoghq.com/api/v2/metrics/derived-metrics/{metric_name} |
| uk1.datadoghq.com | PUT https://api.uk1.datadoghq.com/api/v2/metrics/derived-metrics/{metric_name} |
| app.ddog-gov.com  | PUT https://api.ddog-gov.com/api/v2/metrics/derived-metrics/{metric_name}      |
| us2.ddog-gov.com  | PUT https://api.us2.ddog-gov.com/api/v2/metrics/derived-metrics/{metric_name}  |

### Overview

Update the definition of an existing derived metric. The `id` in the request body
must match the `metric_name` path parameter. Requires the `Manage Tags for Metrics` permission.

This endpoint requires the `metric_tags_write` permission.

OAuth apps require the `metric_tags_write` authorization [scope](https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/api/latest/scopes.md#metrics) to access this endpoint.

### Arguments

#### Path Parameters

| Field                    | Type   | Description             |
| ------------------------ | ------ | ----------------------- |
| metric_name [*required*] | string | The name of the metric. |

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field | Field                    | Type     | Description                                                                                           |
| ------------ | ------------------------ | -------- | ----------------------------------------------------------------------------------------------------- |
|              | data [*required*]        | object   | Data object for creating or updating a derived metric.                                                |
| data         | attributes [*required*]  | object   | Attributes of a derived metric.                                                                       |
| attributes   | definition [*required*]  | object   | The definition of a derived metric as a formula over one or more queries.                             |
| definition   | formula [*required*]     | string   | The formula that combines the queries into the value of the derived metric.                           |
| definition   | queries [*required*]     | [object] | The list of queries referenced by the formula.                                                        |
| queries      | data_source [*required*] | string   | The data source that the query is run against.                                                        |
| queries      | name [*required*]        | string   | The name used to reference this query from the formula.                                               |
| queries      | query [*required*]       | string   | The query string executed against the data source.                                                    |
| data         | id [*required*]          | string   | The derived metric name used as the resource ID.                                                      |
| data         | type [*required*]        | enum     | The derived metric resource type. Allowed enum values: `derived_metrics`. Default: `derived_metrics`. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "definition": {
        "formula": "a",
        "queries": [
          {
            "data_source": "metrics",
            "name": "a",
            "query": "avg:system.cpu.user{*}"
          }
        ]
      }
    },
    "id": "my.derived.metric",
    "type": "derived_metrics"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="200" %}
OK

{% tabs %}
{% tab label="Model" %}
Response containing a single derived metric.

| Parent field | Field                    | Type     | Description                                                                                           |
| ------------ | ------------------------ | -------- | ----------------------------------------------------------------------------------------------------- |
|              | data [*required*]        | object   | A derived metric resource object.                                                                     |
| data         | attributes [*required*]  | object   | Attributes of a derived metric.                                                                       |
| attributes   | definition [*required*]  | object   | The definition of a derived metric as a formula over one or more queries.                             |
| definition   | formula [*required*]     | string   | The formula that combines the queries into the value of the derived metric.                           |
| definition   | queries [*required*]     | [object] | The list of queries referenced by the formula.                                                        |
| queries      | data_source [*required*] | string   | The data source that the query is run against.                                                        |
| queries      | name [*required*]        | string   | The name used to reference this query from the formula.                                               |
| queries      | query [*required*]       | string   | The query string executed against the data source.                                                    |
| data         | id [*required*]          | string   | The derived metric name used as the resource ID.                                                      |
| data         | type [*required*]        | enum     | The derived metric resource type. Allowed enum values: `derived_metrics`. Default: `derived_metrics`. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "definition": {
        "formula": "a",
        "queries": [
          {
            "data_source": "metrics",
            "name": "a",
            "query": "avg:system.cpu.user{*}"
          }
        ]
      }
    },
    "id": "my.derived.metric",
    "type": "derived_metrics"
  }
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="404" %}
Not Found

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Path parameters
export metric_name="dist.http.endpoint.request"

# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X PUT "https://api.${DD_SITE}/api/v2/metrics/derived-metrics/${metric_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "definition": {
        "formula": "a",
        "queries": [
          {
            "data_source": "metrics",
            "name": "a",
            "query": "avg:system.cpu.user{*}"
          }
        ]
      }
    },
    "id": "my.derived.metric",
    "type": "derived_metrics"
  }
}
EOF
```
{% /tab %}
{% /tabs %}
