# List source fields

List the fields a source's data can be queried by. The list has the fields seen in the source's logs, spans, exceptions or web events in the last 6 hours. Returns every field in one page. A source that received no data in the last 6 hours returns an empty list.

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

[[path_param]]
name = "source_id"
required = true
type = "string"
description = "Source whose fields are listed. Get its ID via [List sources](/docs/logs/api/list-all-existing-sources/)."

[[query_param]]
name = "source_type"
default = "logs"
type = "string"
description = "Which of the source's data to list the fields of. Possible values: `logs`, `spans`, `exceptions`, `web_events`."

[[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 list of source fields."
body = '''
{
  "data": [
    {
      "id": "nginx.status",
      "type": "source_field",
      "attributes": {
        "path": "nginx.status",
        "path_parts": [
          "'nginx'",
          "'status'"
        ],
        "type": "Int64"
      }
    }
  ]
}
'''

[[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 = "The source doesn't exist, or the token can't access it."
body = '''
{
  "errors": "Resource with the provided ID was not found"
}
'''

[[response]]
status = 422
description = "The `source_type` parameter isn't `logs`, `spans`, `exceptions` or `web_events`, or the source has no data of that type. `invalid_values` names it."
body = '''
{
  "errors": "Sorry, some values are incorrect",
  "invalid_values": {
    "source_type": "This source has no spans data."
  }
}
'''
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The ID of the source field, such as `nginx.status`."

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

[[param]]
name = "path"
type = "string"
description = "The field's path in the log or span, such as `nginx.status`."

[[param]]
name = "path_parts"
type = "array of strings"
description = "The path's segments as quoted `JSONExtract` arguments, so `JSONExtract(raw, <the segments joined by commas>, 'Nullable(String)')` reads the field."

[[param]]
name = "attributes.type"
type = "string"
description = "The field's data type, such as `String` or `Int64`."
[/params]

#### Example cURL

[code-tabs]
```shell
[label Span fields]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/sources/123456/fields?source_type=spans" \
  --header "Authorization: Bearer $TOKEN"
```
```shell
[label List source fields]
curl --request GET \
  --url https://telemetry.betterstack.com/api/v4/sources/123456/fields \
  --header "Authorization: Bearer $TOKEN"
```
[/code-tabs]
