# Get a metric

Get one metric of a source or an application, with the expressions to query it with.

[endpoint]
method = "GET"
base_url = "https://telemetry.betterstack.com"
path = "/api/v4/metrics/{id}"

[[path_param]]
name = "id"
required = true
type = "string"
description = "The metric name. Can contain dots."

[[query_param]]
name = "source_id"
type = "string"
description = "Source the metric belongs to. Send this or `application_id`."

[[query_param]]
name = "application_id"
type = "string"
description = "Error tracking application the metric belongs to. Send this or `source_id`."

[[query_param]]
name = "team_id"
type = "string"
description = "Team to use, such as `t123`. Get the ID via [List teams](/docs/uptime/api/teams/list/). Required when you can access more than one team."

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

[responses]
[[response]]
status = 200
description = "Returns the metric."
body = '''
{
  "data": {
    "id": "http_requests_total",
    "type": "source_metric",
    "attributes": {
      "name": "http_requests_total",
      "type": "float64",
      "origin": "ingested",
      "layout": "row-based",
      "aggregations": [
        "avg",
        "max",
        "min"
      ],
      "data_points": 182400,
      "active_series": 37,
      "sql_expression": null,
      "json_dot_notation": null,
      "query_examples": [
        "avgMergeIf(value_avg, name = 'http_requests_total')",
        "avgMergeIf(rate_avg, name = 'http_requests_total')   -- per-second rate, for counters"
      ],
      "labels": [
        "host",
        "method",
        "status"
      ]
    }
  }
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "errors": "Invalid Team API token. How to find your Team API token: https://betterstack.com/docs/logs/api/getting-started/#obtaining-a-logtail-api-token"
}
'''

[[response]]
status = 403
description = "Your role doesn't allow viewing this, or the token can't be used for this API."

[[response]]
status = 404
description = "No source or application with that ID, or no metric with that name in it."

[[response]]
status = 422
description = "Both or neither of `source_id` and `application_id` were sent."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The ID of the metric, such as `http_requests_total`."

[[param]]
name = "type"
type = "string"
description = "Always `source_metric`."

[[param]]
name = "name"
type = "string"
description = "Metric name."

[[param]]
name = "attributes.type"
type = "string"
description = "The data type the metric is stored as. Ingested metrics are `float64`. A user-defined metric has the type its definition sets."

[[param]]
name = "origin"
type = "string"
description = "Where the metric comes from.<br/>Valid values:<br/>`ingested`: The metric was sent to Better Stack as a metric.<br/>`user-defined`: The metric is defined from the source's logs."

[[param]]
name = "layout"
type = "string"
description = "How the metric is stored, which decides how to query it.<br/>Valid values:<br/>`row-based`: The metric shares the `value_*` columns with other metrics and is selected by `name`.<br/>`column-based`: The metric has columns of its own."

[[param]]
name = "aggregations"
type = "array of strings"
description = "Aggregations stored for the metric, such as `avg`, `max` and `min`."

[[param]]
name = "data_points"
type = "integer"
description = "Data points received in the last 24 hours."

[[param]]
name = "active_series"
type = "integer"
description = "Distinct series seen in the last 24 hours."

[[param]]
name = "sql_expression"
type = "string or null"
description = "The SQL expression a user-defined metric is defined by. `null` for an ingested metric or one defined by `json_dot_notation`. Returned by get only."

[[param]]
name = "json_dot_notation"
type = "string or null"
description = "The JSON field a user-defined metric is read from, when it's defined that way. Returned by get only."

[[param]]
name = "query_examples"
type = "array of strings"
description = "Expressions to select the metric with in a metrics query. Returned by get only."

[[param]]
name = "labels"
type = "array of strings or null"
description = "Labels seen on an ingested metric in the last 24 hours. `null` for a user-defined metric. Returned by get only."
[/params]

#### Example cURL

```shell
[label Get a metric]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/metrics/http_requests_total?source_id=123456" \
  --header "Authorization: Bearer $TOKEN"
```
