# Update a metric

Updates an existing metric. At least one of `name`, `sql_expression`, `type`, or `aggregations` must be provided.

[endpoint]
base_url = "https://telemetry.betterstack.com"
path = "/api/v2/sources/{source_id}/metrics/{id}"
method = "PATCH"

[[path_param]]
name = "source_id"
description = "Source for which to update a metric"
required = true
type = "integer"

[[path_param]]
name = "id"
description = "ID of the metric you want to update"
required = true
type = "string"

[[body_param]]
name = "name"
description = "Metric name"
required = false
type = "string"

[[body_param]]
name = "sql_expression"
description = "SQL expression to use for the metric"
required = false
type = "string"

[[body_param]]
name = "aggregations"
description = "Aggregations to apply to the metric. <br> Valid aggregations are avg, count, uniq, max, min, anyLast, sum, p50, p90, p95, p99"
required = false
type = "array"

[[body_param]]
name = "type"
description = "Metric type. <br> Valid types are `string_low_cardinality`, `int64_delta`, `float64_delta`, `datetime64_delta`, and `boolean`"
required = false
type = "string"

[[body_param]]
name = "build_type"
description = "How to process historical data. `new_data` (default) applies the change going forward. `historical_logs` reprocesses retained logs."
required = false
type = "string"

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 200
description = ''''''
body = '''
{
"data":
{
"id": "g-123",
"type": "metric",
"attributes": {
"name": "level",
"sql_expression": "JSONExtract(raw, 'level', 'Nullable(String)')",
"aggregations": [],
"type": "string_low_cardinality"
}}}
'''

[[response]]
status = 404
description = '''The source does not have a metric with the given ID'''
body = '''{
"errors": "Resource with provided ID was not found"
}'''
[/responses]

#### Example cURL

```shell
[label Example]
curl --request PATCH \
  --url https://telemetry.betterstack.com/api/v2/sources/123/metrics/g-456 \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "log_type"
  }'
```
