# Dynatrace

> Query Dynatrace observability - problems, metrics, monitored entities, events and SLOs - via the Environment API v2.

Lets an agent read your Dynatrace observability data through the Environment API v2: list and get problems, query metrics and browse metric descriptors, list and get monitored entities, list events, and list SLOs. Useful for incident triage and health checks from a workflow.

## What it can do

| Method | What it does |
| --- | --- |
| `dynatrace_problems_list` | List problems (filter by selector, entity, timeframe). |
| `dynatrace_problem_get` | Get one problem by ID. |
| `dynatrace_metrics_query` | Query metric data points by metric selector. |
| `dynatrace_metrics_descriptors` | List available metrics (descriptors). |
| `dynatrace_entities_list` | List monitored entities by entity selector. |
| `dynatrace_entity_get` | Get one monitored entity by ID. |
| `dynatrace_events_list` | List events (filter by selector, entity, timeframe). |
| `dynatrace_slos_list` | List SLOs (service level objectives). |
| `dynatrace_request` | Generic passthrough to any API v2 endpoint for full API coverage. |

## How to get your credentials

Dynatrace authenticates with an **API token** sent as the `Authorization: Api-Token <token>` header. You also need your **environment URL**.

1. Open your Dynatrace environment.
2. Go to **Access Tokens** (Settings -> Integration -> Dynatrace API, or search "Access tokens").
3. Generate a token and select the read scopes you need: `problems.read`, `metrics.read`, `entities.read`, `events.read`, `slo.read` ([authentication docs](https://docs.dynatrace.com/docs/dynatrace-api/basics/dynatrace-api-authentication)).
4. Copy the token - it is shown once.
5. Copy your **environment URL** from the browser, e.g. `https://abc12345.live.dynatrace.com` (do not append `/api/v2` - FlyMyAI adds that).
6. Paste both into FlyMyAI.

## Fields to fill

| FlyMyAI field | Where it comes from |
| --- | --- |
| `DYNATRACE_API_TOKEN` | Dynatrace -> Access Tokens (with the read scopes above) |
| `DYNATRACE_ENV_URL` | Your environment URL, e.g. `https://abc12345.live.dynatrace.com` |

## Troubleshooting

- **`401 Unauthorized`** - the token is wrong or expired. Generate a new one under Access Tokens.
- **`403 Forbidden`** - the token is missing the scope for that call. Add the matching `*.read` scope (e.g. `metrics.read`) and re-issue.
- **Connection errors / 404 on every call** - the environment URL is wrong. Use the environment root (e.g. `https://abc12345.live.dynatrace.com`), not a sub-path, and do not append `/api/v2`.
- **Empty metric results** - widen the timeframe (`from`/`to`, e.g. `now-2h`) and check the metric selector with `dynatrace_metrics_descriptors`.

## Links

- [Dynatrace API documentation](https://docs.dynatrace.com/docs/dynatrace-api)
- [API authentication & tokens](https://docs.dynatrace.com/docs/dynatrace-api/basics/dynatrace-api-authentication)
