# Publishing

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

Publish an itinerary's draft, edit it after a publish, take it down, and handle the refusals a publish can meet.

An itinerary is a draft that only your organization's members see. Publishing copies the draft into a publication, which is what embeds, share links, route files and tiles show. Publishing needs Map Publishing in your agreement.

## Before you start

Writes act as a member, so mint a session token that names one, 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 below publish `$ITINERARY_ID`, an itinerary of yours with at least one segment.

### No itinerary yet? Create one with a segment

**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]]}}'
```

**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],
      ],
    },
  },
});
```

**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()
```

## Publish

`POST` on the itinerary's publication publishes its current draft. It takes no body and is safe to repeat.

**cURL**

```bash
curl -s -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)" \
  | jq '.data | {status, published_at, has_unpublished_changes}'
```

**TypeScript**

```typescript
const { data: published } = await mountaya.studio.itineraries.postItineraryPublication({
  itinerary_id: itineraryId,
});

console.log(published.status, published.published_at, published.has_unpublished_changes);
```

**Python**

```python
published = 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,
).json()["data"]

print(published["status"], published["published_at"], published["has_unpublished_changes"])
```

**Response (abridged)**

```json
{
  "status": "published",
  "published_at": "2026-11-09T11:04:04.139845Z",
  "has_unpublished_changes": false
}
```

- `POST /v1/itineraries/{itinerary_id}/publication` sets the publication to the current draft: the draft is copied into the next publication, and every published output (the hosted embed, share links, exports and tiles made without a member's session) serves that copy until the next publish. The studio always reads and writes the draft.
- It answers `200 OK` with the whole `ItineraryWithDetails`, `status`, `published_at` and `has_unpublished_changes` reflecting the new publication. Sent again with nothing changed in between, it leaves what readers are served as it is.
- Publishing copies content rather than referencing it, so a later edit, even deleting a segment, never alters what is published. One publication is retained, the most recent: there is no version history. The publication number only ever climbs and is never reissued.
- It needs the `studio-embedded` scope and a session token minted for `studio-embedded` naming a member with a write role, Map Studio and Map Publishing. Publishing charges nothing.
- It moves the itinerary's `etag`. Send the `ETag` you read as `If-Match` to publish only that version; a stale tag is `412` and nothing is published. See [conditional writes](https://docs.mountaya.com/en/apis/conventions/conditional-writes.md).

## Edit after a publish

Edits change the draft only. The itinerary reports `has_unpublished_changes` until you publish again.

**cURL**

```bash
curl -s -X PATCH https://api.mountaya.com/v1/itineraries/$ITINERARY_ID \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"description": "Day one, through Chamonix."}' \
  | jq '.data | {description, status, has_unpublished_changes}'
```

**TypeScript**

```typescript
const { data: edited } = await mountaya.studio.itineraries.patchItinerary({
  itinerary_id: itineraryId,
  body: { description: "Day one, through Chamonix." },
});

console.log(edited.status, edited.has_unpublished_changes);
```

**Python**

```python
edited = requests.patch(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={"description": "Day one, through Chamonix."},
    timeout=30,
).json()["data"]

print(edited["status"], edited["has_unpublished_changes"])
```

**Response (abridged)**

```json
{
  "description": "Day one, through Chamonix.",
  "status": "published",
  "has_unpublished_changes": true
}
```

Visitors still see the published version. Publish again to show the edit.

- Every accepted `PATCH` writes a new revision, even one that changes nothing: it raises `revision`, moves `updated_at` and, on a published itinerary, sets `has_unpublished_changes`. So do segment, waypoint and group writes.
- A member's session token reads the draft. A publishable key alone, a session token minted without `user_id`, and a share token read the publication. A member's token reads the publication too with `?surface=published` on `GET /v1/itineraries/{itinerary_id}`.
- A published snapshot carries its own segment and waypoint ids, which differ from the draft's and change at every publish. Take a `segment_id` for an export from a read of the version that export reads.

## Take it down

`DELETE` on the publication stops serving the itinerary. The draft stays, and you can publish it again later.

**cURL**

```bash
curl -s -X DELETE 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)" \
  | jq '.data | {status, published_at}'
```

**TypeScript**

```typescript
const { data: withdrawn } = await mountaya.studio.itineraries.deleteItineraryPublication({
  itinerary_id: itineraryId,
});

console.log(withdrawn.status, withdrawn.published_at);
```

**Python**

```python
withdrawn = requests.delete(
    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,
).json()["data"]

print(withdrawn["status"], withdrawn["published_at"])
```

**Response (abridged)**

```json
{
  "status": "draft",
  "published_at": null
}
```

- Taking it down acts on a state: an itinerary that is not published answers `200` as well, so a repeat is harmless.
- It is never refused for a collaboration lock, for Map Studio, for Map Publishing or for the `published-itineraries` limit, and it frees the itinerary's place under that limit at once. The only `402` it answers is the missing Embedded Studio every `studio-embedded` operation shares.
- Mountaya stops serving the publication from the next request: embeds and share links stop resolving it, and a read with the key alone answers `404`. A shared cache between a reader and Mountaya may keep serving an answer it holds until that answer's lifetime runs out: at most 6 minutes for a published read of the itinerary or its pace (`max-age=300`, `stale-while-revalidate=60`), and 5 for a public tile (`max-age=300`).
- The publication is kept, not deleted, so publishing again creates the next publication number rather than reusing the old one.

## When a publish is refused

| Status | Code | Why | Do |
| --- | --- | --- | --- |
| `409` | `CONFLICT` | The itinerary has no segments | Add a segment |
| `409` | `CONFLICT` | A collaborator is editing it in Map Studio | Retry once they finish |
| `402` | `PAYMENT_REQUIRED` | Your agreement does not include Map Publishing | [Talk to us](https://mountaya.com/en/contact/) |
| `429` | `LIMIT_REACHED` | You publish as many itineraries as your agreement allows | Take one down, or raise the limit |
| `412` | `PRECONDITION_FAILED` | The itinerary changed since you read it | Read it again |

A collaborator's edit names them in the answer:

**Response**

```json
{
  "errors": [
    {
      "message": "An edit is in progress. Finish it before publishing.",
      "extensions": { "code": "CONFLICT" }
    }
  ],
  "extensions": {
    "metadata": {
      "holder": { "id": "7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1" }
    }
  }
}
```

- When more than one refusal applies, the order is: the missing Embedded Studio product (`402`), the missing Map Studio product (`402`), the missing Map Publishing product (`402`), an itinerary with no segments (`409`), a held collaboration lock (`409`), the `published-itineraries` limit (`429` coded `LIMIT_REACHED`, with no `Retry-After`), and last a stale `If-Match` (`412`).
- The segments are counted again as the publication is taken, so a last segment deleted while the publish runs is the same `409`.
- The lock refusal applies when ANY segment, waypoint or segment group of the itinerary is locked in the collaboration session, including by the member the session token names: a held lock is an edit not yet committed. The holder is at `extensions.metadata.holder.id`. A lock lapses 60 seconds after its holder's editor stream ends.
- The `published-itineraries` limit allows none until the agreement names a number. It refuses a first publish only: republishing an itinerary already live never meets it, and two publishes sent at once cannot both take the last place. Its `429` names no wait and is never retried as it stands: take an itinerary down, or change the agreement, then publish again.
- A personal itinerary, owned by no organization, is never published: `403`.
- See [errors](https://docs.mountaya.com/en/apis/conventions/errors.md) for the envelope and every code.

## Zones

A zone publishes the same way, at `/v1/zones/{zone_id}/publication`. Collection embeds and collection share links show a zone once it is published and public.

- `POST /v1/zones/{zone_id}/publication` and `DELETE` on the same path follow the itinerary's rules: a write role, Map Studio and Map Publishing, no lock held on the zone (`postZoneCollab` locks zones), and `If-Match` to publish the version you read.
- The agreement's `published-zones` limit is separate from `published-itineraries`, allows none until the agreement names a number, and is `429` coded `LIMIT_REACHED`, with no `Retry-After`, on a first publish past it.
- A new zone is private (`is_private: true`). Privacy is read from the draft and takes effect at once, without publishing again. A zone has no share link, route file or video of its own: share it through a collection. See [Map Publishing](https://docs.mountaya.com/en/map-publishing.md#publish-a-zone).

## Next steps

- [Collections and share links](https://docs.mountaya.com/en/apis/map-studio/sharing.md): Share what you publish with the people you choose.
- [Embed the map](https://docs.mountaya.com/en/map-publishing/quickstart.md): Show your published itinerary on your own site.
