# Itineraries

> Canonical URL: https://docs.mountaya.com/en/apis/data/itineraries/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Read a saved itinerary in full, and prepare it as a route file to download.

Two queries read the itineraries you already have: `itinerary` returns one in full, and `exportItinerary` prepares it as a route file. To create or edit an itinerary, use the [Map Studio API](https://docs.mountaya.com/en/apis/map-studio.md).

## Set up

Every sample on this page reuses this setup. It mints a session token with your secret key, so run it on your server.

**cURL**

```bash
export MOUNTAYA_PUBLISHABLE_KEY="pk_your_publishable_key"
export MOUNTAYA_DATA_TOKEN=$(curl -s -X POST https://api.mountaya.com/v1/sessions \
  -H "X-API-Key: $MOUNTAYA_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"publishable_key\": \"$MOUNTAYA_PUBLISHABLE_KEY\"}" | jq -r .data.token)
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const publishableKey = process.env.MOUNTAYA_PUBLISHABLE_KEY ?? "";
const secretKey = process.env.MOUNTAYA_SECRET_KEY ?? "";

const server = new Mountaya({ credential: { secretKey } });
const { data: session } = await new MountayaAdmin(server).sessions.postSession({
  body: { publishable_key: publishableKey },
});

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken: session.token },
});
```

**Python**

```python
import os
import requests

session = requests.post(
    "https://api.mountaya.com/v1/sessions",
    headers={"X-API-Key": os.environ["MOUNTAYA_SECRET_KEY"]},
    json={"publishable_key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"]},
    timeout=10,
).json()["data"]
```

This token is minted without `user_id`, so it reads your itineraries as last published. To read drafts, mint it with a member's `user_id`, as [authentication](https://docs.mountaya.com/en/authentication.md) shows.

## itinerary

Read one itinerary with its segments and waypoints. Replace the id with one of yours: [`search`](https://docs.mountaya.com/en/apis/data/places.md#search) finds it by name.

**cURL**

```bash
curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_DATA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query Itinerary($input: ItineraryInput!) { itinerary(input: $input) { name activitySlug distance ascent segments { name distance duration } waypoints { name point } } }",
    "variables": {
      "input": { "id": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21" }
    }
  }'
```

**TypeScript**

```typescript
const saved = await mountaya.data.itinerary(
  { id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21" },
  {
    select: {
      name: true,
      activitySlug: true,
      distance: true,
      ascent: true,
      segments: { name: true, distance: true, duration: true },
      waypoints: { name: true, point: true },
    },
  },
);

for (const segment of saved.segments) {
  console.log(segment.name, segment.distance);
}
```

**Python**

```python
query = """
query Itinerary($input: ItineraryInput!) {
  itinerary(input: $input) {
    name activitySlug distance ascent
    segments { name distance duration }
    waypoints { name point }
  }
}
"""

result = requests.post(
    "https://data.mountaya.com/graphql",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
    },
    json={
        "query": query,
        "variables": {"input": {"id": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21"}},
    },
    timeout=30,
).json()

if "errors" in result:
    raise RuntimeError(result["errors"])
for segment in result["data"]["itinerary"]["segments"]:
    print(segment["name"], segment["distance"])
```

**Response**

```json
{
  "data": {
    "itinerary": {
      "name": "Docs Tour du Mont-Blanc",
      "activitySlug": "HIKING_AND_TRAIL",
      "distance": 16152.93,
      "ascent": 941,
      "segments": [
        {
          "name": "Day 1: Col de Voza",
          "distance": 4477.94,
          "duration": 7650.52
        },
        {
          "name": "Day 2: Les Contamines",
          "distance": 11674.99,
          "duration": 11698.57
        }
      ],
      "waypoints": [
        {
          "name": "Col de Voza",
          "point": [6.7621, 45.8842]
        }
      ]
    }
  }
}
```

Segments come in order, with distances in meters and durations in seconds. Select a segment's `geometry` to draw it, and `groups` for named legs such as "Day 1".

- `itinerary(input: ItineraryInput!)` takes one field, `id`, a UUID in canonical form. The whole itinerary comes back, with no windowing to declare.
- Access follows the same three-tier visibility model as everything else. Your organization's itineraries, public or private, are readable by id, and another organization's only when it is public, as it was last published. A token naming a member reads your organization's drafts. Under a session token minted without `user_id`, both queries read as a publishable key alone does: your organization's itineraries as last published, never a draft. See [what a bare publishable key reaches](https://docs.mountaya.com/en/authentication.md#what-a-bare-publishable-key-reaches).
- An itinerary you may not read and an id no itinerary carries both answer **not found**, so the answer never confirms that an itinerary exists. Wherever the published version is read, one never published or taken down, or whose organization's agreement does not include Map Publishing, answers **not found** too. A personal itinerary, made from an individual account and owned by no organization, is read as published, which it never is, so it answers **not found** to every key. The token Mountaya's MCP server holds reads the draft. Another organization's private itinerary is never served. The code is `NOT_FOUND`.
- An itinerary of more than 500,000 positions, every position of its segments' geometry, the vias of its routed lines included, plus one per waypoint, is more than one answer carries. The field is refused with `PAYLOAD_TOO_LARGE` at `["input"]`, naming none of its fields, and the rest of the request runs. The positions are counted over the whole itinerary before anything is loaded, whatever your selection asks for, so a narrower selection does not get past it, and the refusal comes after every other, **not found** included.
- Result fields: `id`; `name`, `description`, `activitySlug` (`description` and `activitySlug` null when none is stored); `distance` and `ascent`, totals across every segment in meters, null when no segment contributes (an itinerary with no segments yet); `isPrivate` and `organizationId`.
- `segments`: the ordered chain, each with `id`, `name`, `description`, `position`, `groupId`, metrics (`distance`, `duration`, `ascent`, `descent`, `altitude { min max }`, `gradient { min max }`) and its GeoJSON `geometry`. A segment not yet computed carries null metrics; one with no geometry yet carries a null `geometry`.
- `waypoints`: named points in order, each with `id`, `name`, `description`, `position`, `point`, `amenities`, `timing { cutoffAt stopDuration }`, `contact`, `media` and `properties`.
- `groups`: the segment groups, oldest first, each with `id`, `name`, `color` and `speed`. A group renames and recolours a contiguous run of segments so it reads as one leg ("Day 1"), and can override the speed used for its duration. Membership is carried on each segment's `groupId` rather than nested inside the group, so the ordered segment chain stays the primary structure. Resolve a run by matching ids.
- `segmentCount`, `waypointCount`, `groupCount`: the length of each list, so a client can size a response without walking it.
- To answer questions about the ground a saved route covers with [`terrainProfile`](https://docs.mountaya.com/en/apis/data/terrain.md#terrainprofile) or [`analyzeGeometry`](https://docs.mountaya.com/en/apis/data/analysis.md), take the segment's `LineString` (its `geometry` itself, or the `GeometryCollection`'s `LineString` member), reduce each position to `[longitude, latitude]`, and send those as `coordinates`, at most 10,000 at a time. Both queries take exactly two numbers per position, and a saved segment's positions carry altitude. Sent as it comes, a segment is refused `VALIDATION_FAILED` at `["input", "coordinates", 0]`.
- `itinerary` is the companion to the `itineraries` target of [`search`](https://docs.mountaya.com/en/apis/data/places.md#search), which returns references only.
- The id in the samples is the canonical placeholder, and the response was read from an itinerary of a test organization.

## exportItinerary

Prepare an itinerary as a route file. The query answers a short-lived download link, not the file itself.

```graphql
query ExportItinerary {
  exportItinerary(input: { id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", format: GPX }) {
    url
    filename
    format
    expiresAt
  }
}
```

Fetch `url` before `expiresAt` to download the file. `format` takes `GPX`, `KML`, `KMZ`, `GEOJSON`, `CSV`, `FIT`, or `TCX`.

> **Treat the URL as a password**
>
> Anyone holding the link can download the file until it expires, within minutes. Do not log it, cache it, or store it.

- `exportItinerary(input: ExportItineraryInput!)` takes the `id` of an itinerary you can already read, a `format` (`GPX`, `KML`, `KMZ`, `GEOJSON`, `CSV`, `FIT`, `TCX`), and an optional `variant` that picks between a planned course and a completed activity for `FIT` and `TCX`. Nothing here widens access.
- It returns `url`, the suggested `filename` with its extension, `format` echoed back, and `expiresAt`, an RFC 3339 timestamp. Treat `expiresAt` as the authority on the window rather than assuming a duration. `@mountaya/client` decodes `expiresAt` to a `Date`.
- The query returns a signed URL, not the file. The URL carries no authentication of its own, so anyone holding it can fetch the file until it expires. It names one itinerary in one format, and it re-checks your access when fetched, so a link that leaks after your access changed is already dead.
- Under a token naming a member, an itinerary of your own organization is exported as its current draft, and only while your organization holds [Map Publishing](https://docs.mountaya.com/en/map-publishing.md): otherwise the query answers `PAYMENT_REQUIRED` and mints no URL. Under a token minted without `user_id` it is exported as it was last published. Another organization's public itinerary is exported as it was last published.
- An itinerary of more than 500,000 positions, counted as `itinerary` counts them, is refused with `PAYLOAD_TOO_LARGE` at `["input"]`, after every other refusal, and no URL is minted.
- A download gives again, as they are, the refusals the query gives for the itinerary when they have come to apply since the URL was minted: a `402` for a draft whose organization no longer holds Map Publishing, and a `413` for an itinerary grown past 500,000 positions.
- An export stores nothing and creates no share link, so the same itinerary can be prepared repeatedly in different formats.
- A deployment with no export signing secret answers `NOT_IMPLEMENTED` and mints no URL.

## Next steps

- [Terrain](https://docs.mountaya.com/en/apis/data/terrain.md): Profile a segment's line for elevation and slope.
- [Map Studio API](https://docs.mountaya.com/en/apis/map-studio.md): Create, edit, and publish the itineraries these queries read.
