# Get a service map

Get a source's service map for a time range, as the **Service map** page shows it. The map is drawn from a collector source's metrics, or from a source's traces. Set `service` to get one node's callers and dependencies.

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

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

[[query_param]]
name = "start_time"
type = "string"
description = "Start of the time range. Accepts an ISO 8601 timestamp, in UTC when it has no time zone, a relative time like `now-1h` or `now-2h45m`, or a Unix timestamp in seconds, milliseconds, microseconds or nanoseconds. Defaults to `now-1h`."

[[query_param]]
name = "end_time"
type = "string"
description = "End of the time range, in the same forms as `start_time`. Must be after `start_time`. Defaults to `now`."

[[query_param]]
name = "display_mode"
default = "services"
type = "string"
description = "Whether the map's nodes are services or hosts, as the map's toggle sets them. A map drawn from traces accepts `services` only. Possible values: `services`, `hosts`."

[[query_param]]
name = "depth"
type = "integer"
description = "How many connections away from `service` a node can be and stay on the map, from 1 to 3. Needs `service`. Defaults to `1`."

[[query_param]]
name = "service"
type = "string"
description = "The `name` of the service or host to center the map on. The map then shows only that node and the nodes within `depth` connections of it, in either direction, and the connections between them."

[[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 service map."
body = '''
{
  "data": {
    "id": "123456",
    "type": "service_map",
    "attributes": {
      "source_id": "123456",
      "display_mode": "services",
      "nodes": [
        {
          "name": "checkout",
          "kind": "service",
          "platform": "golang",
          "containers": [
            "checkout"
          ],
          "listen_addresses": [
            "172.19.0.12:5050"
          ]
        },
        {
          "name": "orders",
          "kind": "queue",
          "platform": "kafka",
          "containers": [],
          "listen_addresses": []
        }
      ],
      "connections": [
        {
          "source": "checkout",
          "destination": "astronomy-db",
          "destination_address": "172.19.0.14:5432",
          "external": false,
          "protocols": [
            "Postgres"
          ],
          "requests_per_second": 0.041066,
          "server_error_share": 0,
          "client_error_share": 0,
          "duration_p50_ms": 5.0,
          "duration_p95_ms": 5.0,
          "duration_p99_ms": 25.0,
          "duration_p50_lower_bound": null,
          "duration_p95_lower_bound": null,
          "duration_p99_lower_bound": null
        },
        {
          "source": "ad",
          "destination": "flagd",
          "destination_address": "172.19.0.19:8013",
          "external": false,
          "protocols": [
            "HTTP"
          ],
          "requests_per_second": 0.001674,
          "server_error_share": 0.16665,
          "client_error_share": 0,
          "duration_p50_ms": 25.0,
          "duration_p95_ms": 10000.0,
          "duration_p99_ms": 10000.0,
          "duration_p50_lower_bound": null,
          "duration_p95_lower_bound": null,
          "duration_p99_lower_bound": null
        }
      ]
    }
  }
}
'''

[[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 = "With an OAuth token, the user's role doesn't grant Live tail in the source's team, or the API token's scopes don't include this product."
body = '''
{
  "errors": "You don't have permission to view live tail in this team. Your Better Stack role restricts this action. Ask an organization admin to update your role's permissions."
}
'''

[[response]]
status = 404
description = "The `source_id` value isn't one of your sources. Find your sources via [List sources](/docs/logs/api/list-all-existing-sources/)."
body = '''
{
  "errors": "Resource with the provided ID was not found"
}
'''

[[response]]
status = 422
description = "The source has no service map, a parameter is unknown, or a value is refused and `invalid_values` names it. A map needs a collector source, or a source whose traces have the labels the map uses. `display_mode` is refused when it isn't `services` or `hosts`, and `hosts` is refused on a map drawn from traces. `service` is refused when it isn't a node on the map in the time range, and `depth` when it isn't from 1 to 3 or comes without `service`. `start_time` or `end_time` is refused when it's invalid or `end_time` isn't after `start_time`."
body = '''
{
  "errors": "Sorry, some values are incorrect",
  "invalid_values": {
    "source_id": "The service map is drawn from a collector source, or from a source whose traces carry the labels the map reads."
  }
}
'''

[[response]]
status = 422
description = "The time range holds too much data to read. `errors` says why, and `refusal` lists time windows that each fit, the same way [Run a query](/docs/logs/api/query/) does. Ask for a shorter time range."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The ID of the service map, such as `123456`."

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

[[param]]
name = "source_id"
type = "string"
description = "The ID of the source the map is drawn from."

[[param]]
name = "display_mode"
type = "string"
description = "Whether the map's nodes are services or hosts. A map drawn from traces is always `services`. Possible values: `services`, `hosts`."

[[param]]
name = "nodes"
type = "array of objects"
description = "The services or hosts on the map, sorted by name."

[[param]]
name = "nodes[].name"
type = "string"
description = "The node's name. The `entry` node is named `Unknown`."

[[param]]
name = "nodes[].kind"
type = "string"
description = "What the node is.<br/>Valid values:<br/>`service`: A service.<br/>`host`: A host.<br/>`database`: A database, drawn from the traces of the services that call it.<br/>`queue`: A message queue, drawn from the traces of the services that call it.<br/>`entry`: Stands for requests from outside the traced services, such as users or callers that send no traces."

[[param]]
name = "nodes[].platform"
type = "string or null"
description = "What the node runs, such as `golang`, `java`, `postgres` or `kafka`, as the collector or the traces report it. `null` when it isn't known, or for a host whose applications run on different platforms."

[[param]]
name = "nodes[].containers"
type = "array of strings"
description = "The containers of the service, or on the host. On a map drawn from traces, the service's processes."

[[param]]
name = "nodes[].listen_addresses"
type = "array of strings"
description = "The addresses the node listens on, each an IP address and port. On a map drawn from traces, the host names its callers reach it by."

[[param]]
name = "nodes[].requests_per_second"
type = "number or null"
description = "Average requests per second into the node, summed over its incoming connections. `null` when no incoming requests were measured."

[[param]]
name = "nodes[].server_error_share"
type = "number or null"
description = "Share of the node's incoming requests that failed with a server error, from 0 to 1. `null` when no incoming requests were measured."

[[param]]
name = "nodes[].client_error_share"
type = "number or null"
description = "Share of the node's incoming requests that failed with a client error, from 0 to 1. `null` when no incoming requests were measured."

[[param]]
name = "nodes[].outbound_requests_per_second"
type = "number or null"
description = "Average rate of the requests the node makes, per second, summed over its outgoing connections. `null` when no outgoing requests were measured."

[[param]]
name = "connections"
type = "array of objects"
description = "The connections from each node, sorted by `source` and `destination`."

[[param]]
name = "connections[].source"
type = "string"
description = "The name of the node that makes the calls."

[[param]]
name = "connections[].destination"
type = "string"
description = "The name of the node called. An outside address is named by its DNS name with the port, or by its IP address and port when DNS gives no name. `unknown` when the address isn't known. On a map drawn from traces, an outside address is the host called."

[[param]]
name = "connections[].destination_address"
type = "string or null"
description = "The IP address and port called. On a map drawn from traces, the host, queue or service called. `null` when it isn't known."

[[param]]
name = "connections[].external"
type = "boolean"
description = "Whether the destination is an outside address rather than a node on the map."

[[param]]
name = "connections[].protocols"
type = "array of strings"
description = "The protocols seen on the connection, such as `HTTP`, `Postgres`, `Redis` or `Kafka`."

[[param]]
name = "connections[].requests_per_second"
type = "number or null"
description = "Average requests per second in the time range. `null` when no requests were measured."

[[param]]
name = "connections[].server_error_share"
type = "number or null"
description = "Share of requests that failed with a server error, from 0 to 1. A server error is an HTTP 5xx response or a gRPC status such as `UNAVAILABLE` or `INTERNAL`. `null` when no requests were measured."

[[param]]
name = "connections[].client_error_share"
type = "number or null"
description = "Share of requests that failed with a client error, from 0 to 1. A client error is an HTTP 4xx response or any other gRPC status except `OK`. `null` when no requests were measured."

[[param]]
name = "connections[].duration_p50_ms"
type = "number or null"
description = "Median request duration in milliseconds, as the upper bound of the histogram bucket it falls in. `null` when no durations were measured. When `duration_p50_lower_bound` is `true`, the value is the highest bucket bound and the real duration is higher."

[[param]]
name = "connections[].duration_p95_ms"
type = "number or null"
description = "95th percentile of request duration in milliseconds, as the upper bound of the histogram bucket it falls in. `null` when no durations were measured. When `duration_p95_lower_bound` is `true`, the value is the highest bucket bound and the real duration is higher."

[[param]]
name = "connections[].duration_p99_ms"
type = "number or null"
description = "99th percentile of request duration in milliseconds, as the upper bound of the histogram bucket it falls in. `null` when no durations were measured. When `duration_p99_lower_bound` is `true`, the value is the highest bucket bound and the real duration is higher."

[[param]]
name = "connections[].duration_p50_lower_bound"
type = "boolean or null"
description = "Whether the median is above the histogram's highest bucket bound, so the real value is higher than `duration_p50_ms`. `null` on a map drawn from a collector."

[[param]]
name = "connections[].duration_p95_lower_bound"
type = "boolean or null"
description = "Whether the 95th percentile is above the histogram's highest bucket bound, so the real value is higher than `duration_p95_ms`. `null` on a map drawn from a collector."

[[param]]
name = "connections[].duration_p99_lower_bound"
type = "boolean or null"
description = "Whether the 99th percentile is above the histogram's highest bucket bound, so the real value is higher than `duration_p99_ms`. `null` on a map drawn from a collector."
[/params]

#### Example cURL

[code-tabs]
```shell
[label Hosts in the last hour]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/sources/123456/service-map?display_mode=hosts" \
  --header "Authorization: Bearer $TOKEN"
```
```shell
[label Callers and dependencies of one service]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/sources/123456/service-map?start_time=now-6h&service=checkout" \
  --header "Authorization: Bearer $TOKEN"
```
[/code-tabs]
