> For the complete documentation index, see [llms.txt](https://integrations.drivetrain.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/quickstart.md).

# Quickstart

Go from an API key to metric values in four calls, with curl and Python examples.

This walk-through pulls quarterly revenue by region for your live model and one budget version. It takes four calls: versions, scenarios, metrics, then values.

{% hint style="info" %}
**Before you start**

* You have the **Admin** role, and your subscription includes Drivetrain API access. See [Authentication and API keys](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/authentication-and-api-keys.md).
* You know your base URL: `https://{your_subdomain}.drivetrain.ai/drive/api/v1/public`, or `https://{your_subdomain}.eu.drivetrain.ai/drive/api/v1/public` for an EU workspace.
  {% endhint %}

## 1. Get your API key

Navigate to **Settings** > **API Key** and click **Copy**. Store it in an environment variable rather than in your code:

```bash
export DRIVETRAIN_API_KEY='{your_apikey}'
export DRIVETRAIN_BASE='https://{your_subdomain}.drivetrain.ai/drive/api/v1/public'
```

## 2. Check the key and find version names

```bash
curl "$DRIVETRAIN_BASE/versions" --header "apikey: $DRIVETRAIN_API_KEY"
```

A `200` with a `data` array means the key works. Note the `name` of each version you want (for example `Budget_2026`). `Current` is your live model. A `401` or `403` means the key, role or subscription isn't right: see [Errors and troubleshooting](https://github.com/DrivetrainAi/gitbook-integrations/tree/main/en/extending-drivetrain/drivetrain-api/errors-and-troubleshooting.md#troubleshooting).

## 3. Find scenario names

```bash
curl "$DRIVETRAIN_BASE/scenarios" --header "apikey: $DRIVETRAIN_API_KEY"
```

Skip this if you only need the base case: [Get metrics bulk data API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-metrics-bulk-data-api.md) uses `Base_Case` when you don't send `scenarios`.

## 4. Find metric and dimension names

```bash
curl "$DRIVETRAIN_BASE/metrics" --header "apikey: $DRIVETRAIN_API_KEY"
```

For each metric you want, note:

* `name`, for example `metrics.Revenue`.
* `versions[].dimensions`, the dimensions you can break it down by in each version.
* Whether `versions[].name` includes `Current` or `Actual`. Only those metrics return values.

## 5. Pull the values

```bash
curl --request POST "$DRIVETRAIN_BASE/metrics-bulk" \
  --header "apikey: $DRIVETRAIN_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "metricNames": ["metrics.Revenue"],
    "versions": ["Current", "Budget_2026"],
    "granularity": ["QUARTERLY"],
    "startDate": "2026-01-01",
    "endDate": "2026-12-31",
    "dimensions": ["region"]
  }'
```

Each row in `data` is one metric, version, scenario, quarter and region. The response also includes roll-up rows for all regions together, which have no `region` key. Drop them before you add values up (see [Things to check in your results](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-metrics-bulk-data-api.md#things-to-check-in-your-results)).

## The same flow in Python

This example uses the [`requests`](https://pypi.org/project/requests/) library. `json=` sends the body as `Content-Type: application/json`, which [Get metrics bulk data API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-metrics-bulk-data-api.md) requires.

```python
import os
import requests

BASE = os.environ["DRIVETRAIN_BASE"]
HEADERS = {"apikey": os.environ["DRIVETRAIN_API_KEY"]}


def get(path, **params):
    response = requests.get(f"{BASE}{path}", headers=HEADERS, params=params)
    response.raise_for_status()
    return response.json()


versions = [v["name"] for v in get("/versions")["data"]]
metrics = {m["name"]: m for m in get("/metrics")["data"]}

wanted = ["metrics.Revenue"]
live = ("Current", "Actual")
missing = [
    name for name in wanted
    if name not in metrics or not any(v["name"] in live for v in metrics[name]["versions"])
]
if missing:
    raise SystemExit(f"Not in your live model: {missing}")

dimensions = ["region"]
body = {
    "metricNames": wanted,
    "versions": ["Current"] + [v for v in versions if v == "Budget_2026"],
    "granularity": ["QUARTERLY"],
    "startDate": "2026-01-01",
    "endDate": "2026-12-31",
    "dimensions": dimensions,
}
response = requests.post(f"{BASE}/metrics-bulk", headers=HEADERS, json=body)
response.raise_for_status()
rows = response.json()["data"]

# Keep only the detailed rows: drop roll-up totals that lack a dimension key.
detailed = [row for row in rows if all(d in row for d in dimensions)]
for row in detailed:
    print(row["Version"], row["period"], row["region"], row["result"])
```

The roll-up filter assumes every requested dimension applies to the metric. If one doesn't, that metric's rows never carry its key. Check `versions[].dimensions` first.

### Read every value of a dimension

[Get dimension values API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-dimension-values-api.md) is the only paged endpoint. Request pages until `hasMore` is `false`:

```python
def all_dimension_values(dimension, page_size=5000):
    page = 1
    while True:
        body = get(f"/dimensions/{dimension}/values", pageSize=page_size, pageNumber=page)
        yield from body["data"]
        if not body["hasMore"]:
            break
        page += 1


employees = list(all_dimension_values("emp_id"))
```

## Next steps

* Field-by-field reference for each call: see the endpoint pages under [Drivetrain API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api.md).
* Replace a list's rows from your own system: [Upload list CSV API](https://github.com/DrivetrainAi/gitbook-integrations/tree/main/en/extending-drivetrain/drivetrain-api/upload-list-csv-api.md).
* Error messages, their causes and fixes: [Errors and troubleshooting](https://github.com/DrivetrainAi/gitbook-integrations/tree/main/en/extending-drivetrain/drivetrain-api/errors-and-troubleshooting.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/quickstart.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
