# Import and export

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

Export an itinerary as GPX, KML, FIT, TCX and more, import route files as new itineraries, and hand a browser a signed download link.

Take an itinerary out as a route file, and bring route files in as new itineraries. This page exports an itinerary as GPX, then imports that file back. To import a whole folder of files, follow [import a GPX catalog](https://docs.mountaya.com/en/apis/map-studio/gpx-import.md).

## Before you start

Mint a session token that names a member, as in the [quickstart](https://docs.mountaya.com/en/apis/map-studio/quickstart.md):

**cURL**

```bash
export MOUNTAYA_MEMBER_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\", \"user_id\": \"7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1\", \"surface\": \"studio-embedded\"}" \
  | 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 server = new Mountaya({
  credential: { secretKey: process.env.MOUNTAYA_SECRET_KEY ?? "" },
});
const { data: session } = await new MountayaAdmin(server).sessions.postSession({
  body: {
    publishable_key: publishableKey,
    user_id: "7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1",
    surface: "studio-embedded",
  },
});

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

**Python**

```python
import os
import uuid

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"],
        "user_id": "7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1",
        "surface": "studio-embedded",
    },
    timeout=10,
).json()["data"]
```

The examples export `$ITINERARY_ID`, a published itinerary of yours.

### No published itinerary yet? Create one

**cURL**

```bash
ACTIVITY_ID=$(curl -s https://api.mountaya.com/v1/activities \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  | jq -r '.data[].children[] | select(.slug == "hiking-and-trail") | .id')

ITINERARY_ID=$(curl -s -X POST https://api.mountaya.com/v1/itineraries \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"name\": \"Chamonix to Argentière\", \"activity_id\": \"$ACTIVITY_ID\", \"is_private\": false}" \
  | jq -r .data.id)

curl -s -o /dev/null -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"name": "Chamonix to Argentière", "mode": "directions", "geojson": {"type": "MultiPoint", "coordinates": [[6.8712, 45.9231], [6.9271, 45.9822]]}}'

curl -s -o /dev/null -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/publication \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)"
```

**TypeScript**

```typescript
const { data: categories } = await mountaya.studio.activities.getActivities();
const hiking = categories
  .flatMap((category) => category.children)
  .find((activity) => activity.slug === "hiking-and-trail");

const { data: created } = await mountaya.studio.itineraries.postItinerary({
  body: { name: "Chamonix to Argentière", activity_id: hiking?.id ?? "", is_private: false },
});
const itineraryId = created.id;

await mountaya.studio.itineraries.postItinerarySegment({
  itinerary_id: itineraryId,
  body: {
    name: "Chamonix to Argentière",
    mode: "directions",
    geojson: {
      type: "MultiPoint",
      coordinates: [
        [6.8712, 45.9231],
        [6.9271, 45.9822],
      ],
    },
  },
});
await mountaya.studio.itineraries.postItineraryPublication({ itinerary_id: itineraryId });
```

**Python**

```python
categories = requests.get(
    "https://api.mountaya.com/v1/activities",
    headers={"X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"]},
    timeout=30,
).json()["data"]
activity_id = next(
    activity["id"]
    for category in categories
    for activity in category["children"]
    if activity["slug"] == "hiking-and-trail"
)

itinerary_id = requests.post(
    "https://api.mountaya.com/v1/itineraries",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={"name": "Chamonix to Argentière", "activity_id": activity_id, "is_private": False},
    timeout=30,
).json()["data"]["id"]

requests.post(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}/segments",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "name": "Chamonix to Argentière",
        "mode": "directions",
        "geojson": {"type": "MultiPoint", "coordinates": [[6.8712, 45.9231], [6.9271, 45.9822]]},
    },
    timeout=30,
).raise_for_status()

requests.post(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}/publication",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    timeout=30,
).raise_for_status()
```

## Export a route file

`GET /v1/itineraries/{itinerary_id}/export` answers the file itself. With the publishable key alone, it exports the published version.

**cURL**

```bash
curl -s -o chamonix-to-argentiere.gpx \
  "https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/export?format=gpx" \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY"

head -n 8 chamonix-to-argentiere.gpx
```

**TypeScript**

```typescript
import { writeFile } from "node:fs/promises";

const visitor = new Mountaya({ credential: { publishableKey } });
const file = await visitor.studio.itineraries.getItineraryExport({
  itinerary_id: itineraryId,
  query: { format: "gpx" },
});

await writeFile("chamonix-to-argentiere.gpx", Buffer.from(file.bytes));
console.log(file.filename, file.contentType);
```

**Python**

```python
exported = requests.get(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}/export",
    headers={"X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"]},
    params={"format": "gpx"},
    timeout=30,
)
exported.raise_for_status()

with open("chamonix-to-argentiere.gpx", "wb") as gpx:
    gpx.write(exported.content)
```

**Response (first lines)**

```xml
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="Mountaya" xmlns="http://www.topografix.com/GPX/1/1">
  <trk>
    <name>Chamonix to Argentière</name>
    <trkseg>
      <trkpt lat="45.92307" lon="6.87126">
        <ele>1037.1</ele>
      </trkpt>
```

| `format` | File |
| --- | --- |
| `gpx` | One track, one track segment per itinerary segment |
| `kml`, `kmz` | One styled line per segment |
| `geojson` | A `FeatureCollection` |
| `fit`, `tcx` | A course for a GPS watch, or an activity with `variant=activity` |
| `csv` | A flat table of coordinates |

Add `segment_id` to export one segment.

- The body is the file, not a JSON envelope. `Content-Type` names its media type (`application/gpx+xml` for GPX) and `Content-Disposition` its filename, from the itinerary's name. Every format carries track point elevation when the geometry holds it; CSV is lossy.
- `format` is required: `gpx`, `kml`, `kmz`, `geojson`, `fit`, `tcx`, `csv`. `variant` (`course`, the default, or `activity`) applies to `fit` and `tcx` only; with another format it is refused once the itinerary is found.
- Which version is exported follows the credential, as on `GET /v1/itineraries/{itinerary_id}`: a publishable key alone, a session token minted without `user_id`, and a share token (`X-Share-Token`, no key) export the published snapshot; a session token naming a member exports the organization's draft unless `surface=published` is passed. Exporting a draft needs Map Publishing (`402` otherwise); the published snapshot never does.
- An itinerary never published, or taken down, answers `404` whenever the published snapshot is what is served.
- A published snapshot's segment ids differ from the draft's and change at every publish: take `segment_id` from a read of the version you export.
- An itinerary of more than 500,000 positions (every position of its segments' geometry, routed vias included, plus one per waypoint) is `413`.
- Exports are limited to 60 a minute per client IP address under a key alone, a session token minted without `user_id`, or a share token, and to 60 a minute per user under a session token naming one (`429` with `Retry-After`). The limit is checked before the read limits, so an export it refuses spends nothing of them.
- The scope is `publishing` (or `studio-embedded`); a share token needs none.

## Import a route file

Import takes two calls. `POST /v1/itineraries/preview` reads the file and proposes segments without saving anything. `POST /v1/itineraries/import` saves the draft you send back.

**cURL**

```bash
PREVIEW=$(curl -s -X POST https://api.mountaya.com/v1/itineraries/preview \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -F "provider=gpx" \
  -F "file=@chamonix-to-argentiere.gpx" \
  -F "activity_id=$ACTIVITY_ID")

IMPORTED=$(echo "$PREVIEW" \
  | jq '{
      name: "Chamonix to Argentière (GPX)",
      activity_id: .data.activity_id,
      is_private: true,
      segments: [.data.segments[] | {mode: .recommendation, name, geojson: .[.recommendation].geojson}],
      waypoints: .data.waypoints
    }' \
  | curl -s -X POST https://api.mountaya.com/v1/itineraries/import \
    -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
    -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d @-)

echo "$IMPORTED" | jq '.data | {id, name, status, distance, ascent, count}'
IMPORTED_ID=$(echo "$IMPORTED" | jq -r .data.id)
```

**TypeScript**

```typescript
import { readFile } from "node:fs/promises";

const { data: catalog } = await mountaya.studio.activities.getActivities();
const activityId =
  catalog.flatMap((category) => category.children).find((a) => a.slug === "hiking-and-trail")
    ?.id ?? "";

const form = new FormData();
form.append("provider", "gpx");
form.append("activity_id", activityId);
form.append(
  "file",
  new Blob([await readFile("chamonix-to-argentiere.gpx")]),
  "chamonix-to-argentiere.gpx",
);
const { data: preview } = await mountaya.studio.itineraries.postItineraryPreview({ body: form });

const { data: imported } = await mountaya.studio.itineraries.postItineraryImport({
  body: {
    name: "Chamonix to Argentière (GPX)",
    activity_id: preview.activity_id,
    is_private: true,
    segments: preview.segments.map((segment) => {
      const candidate = segment[segment.recommendation] ?? segment.linestring;
      return { mode: candidate.mode, name: segment.name, geojson: candidate.geojson };
    }),
    waypoints: preview.waypoints,
  },
});

console.log(imported.id, imported.distance, imported.count);
```

**Python**

```python
with open("chamonix-to-argentiere.gpx", "rb") as gpx:
    preview = requests.post(
        "https://api.mountaya.com/v1/itineraries/preview",
        headers={
            "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
            "X-Session-Token": session["token"],
            "Idempotency-Key": str(uuid.uuid4()),
        },
        data={"provider": "gpx", "activity_id": activity_id},
        files={"file": ("chamonix-to-argentiere.gpx", gpx)},
        timeout=60,
    ).json()["data"]

imported = requests.post(
    "https://api.mountaya.com/v1/itineraries/import",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "name": "Chamonix to Argentière (GPX)",
        "activity_id": preview["activity_id"],
        "is_private": True,
        "segments": [
            {
                "mode": segment["recommendation"],
                "name": segment["name"],
                "geojson": segment[segment["recommendation"]]["geojson"],
            }
            for segment in preview["segments"]
        ],
        "waypoints": preview["waypoints"],
    },
    timeout=60,
).json()["data"]

print(imported["id"], imported["distance"], imported["count"])
```

**Response (abridged)**

```json
{
  "id": "9b8c5fe6-85dd-4dfd-8ceb-3f5eaceb1dc5",
  "name": "Chamonix to Argentière (GPX)",
  "status": "draft",
  "distance": 9005.15,
  "ascent": 277,
  "count": {
    "groups": 0,
    "segments": 1,
    "waypoints": 0
  }
}
```

Review the preview before you confirm: rename the itinerary, and pick each segment's mode.

- `POST /v1/itineraries/preview` is `multipart/form-data`: `provider` (`gpx`, `geojson`, `kml`, `kmz`, `fit`, `tcx`), `file` (at most 25 MiB, `413` past it), `activity_id` (required: no file format carries an activity), and optional `granularity` (`auto` by default) and `organization_id`. FIT and TCX may be a course or a recorded activity; the type is read from the file. Nothing is saved, so a preview is safe to repeat.
- The preview answers `name` (copied from the file, folded onto a single line as every name is held, otherwise unchecked), `activity_id`, `segments`, `waypoints` and `warnings`. Each proposed segment has a `recommendation` (`directions` or `linestring`), a `recommendation_reason`, and a candidate per mode under `directions` (absent when the stretch cannot be routed) and `linestring`, each with its `mode`, `geojson` and computed metrics. Send a candidate's `geojson` back unchanged.
- A source is split into at most 60 proposed segments and proposes at most 5,000 waypoints (`waypoints-truncated` in `warnings` past that). A source of more than 500,000 points, a freehand stretch over 500 km or 10,000 positions, or one whose duration cannot be stored is `413`: split it, or preview with a finer `granularity`.
- `POST /v1/itineraries/import` creates the itinerary, its segments and its waypoints together or not at all, answering `201 Created` with the whole itinerary. Every field is validated before any routing; every segment's metrics are recomputed server-side. `name` must be 2 to 30 characters and unique in the organization (`409`). A proposal's `color` is empty, which the import refuses: send a color only when you chose one.
- The import is a general "create an itinerary with its details" call: the preview is optional, and a `directions` segment takes a `MultiPoint` of 2 to 45 waypoints, a `linestring` segment a `LineString`. At most 1,000 segments and 5,000 waypoints per request.
- Previews and imports share a limit of 10 requests a minute per user and 60 per organization, and the requests they send the routing engine a limit of 4,000 a minute per user and 24,000 per organization (`429` with `Retry-After` past either). Every request counts: a route, an analysis of a freehand line, and each half of an analysis the engine could not make whole. While it runs, a preview holds 1,188, the most it may send, and an import one for each segment of its draft plus 120; once it ends, whatever its answer, it is charged the ones it sent. A preview of a recording on mapped ways sends a few dozen, and an import refused before it routes, a taken name among them, sends none. A preview and the import of a 1,000-segment draft fit in one minute. Each sends at most 120 requests to analyse in parts a line the engine could not analyse whole, in rounds: every line it could not analyse whole is split in two before any half is split again, the lines first in the file or the draft first where the 120 run out within a round. Past them, a stretch left unanalysed has an unknown surface, way type and difficulty. The routing limit is checked after the request limit, and is apart from the routed segment writes' limit, so editing the itinerary you just imported never meets it. Their routing is recorded as `studio-embedded` data usage and never counted toward the Data API's limits or invoice.
- Both take the `studio-embedded` scope and a member's session token with a write role, and need Map Studio.

## Hand a browser a download link

To let a visitor download the file from your page without a key, ask the Data API's [`exportItinerary`](https://docs.mountaya.com/en/apis/data/itineraries.md#exportitinerary) for a signed URL. The URL works for ten minutes, with no credential.

- `exportItinerary(input: { id, format, variant })` answers `url`, `filename`, `format` and `expiresAt`. `format` is `GPX`, `KML`, `KMZ`, `GEOJSON`, `FIT`, `TCX` or `CSV`; `variant` (`COURSE` by default, or `ACTIVITY`) applies to `FIT` and `TCX` only. It needs the `data` scope and a session token. See [the Data API's itineraries](https://docs.mountaya.com/en/apis/data/itineraries.md#exportitinerary).
- The URL is valid for ten minutes and may be fetched any number of times in that window. `filename` keeps only Latin letters, French accented letters, digits, spaces, dots, underscores and hyphens of the itinerary's name, or `export`.
- A session token naming a member exports the draft (which needs Map Publishing); a token minted without `user_id` exports the published snapshot. Errors arrive under `200` with an `errors` array; `NOT_IMPLEMENTED` means downloads are unavailable on that deployment.

## Next steps

- [Import a GPX catalog](https://docs.mountaya.com/en/apis/map-studio/gpx-import.md): Turn a folder of GPX files into published itineraries.
- [Event streams and sync](https://docs.mountaya.com/en/apis/map-studio/sync.md): Keep a copy of your itineraries up to date.
- [Itineraries on the Data API](https://docs.mountaya.com/en/apis/data/itineraries.md): Read an itinerary and its profile with GraphQL.
