# Edit an itinerary's route

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

Insert, split, merge and convert an itinerary's segments, group them, and mark places along the route with waypoints.

An itinerary's route is a chain of segments, each starting where the one before it ends. A segment is routed along trails or drawn as you give it. Waypoints mark places along the route, and groups give a run of segments one name.

## 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 edit `$ITINERARY_ID`, an itinerary of yours with 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 valley walk\", \"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 valley walk", 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 valley walk", "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()
```

## Read the chain

Read the itinerary for each segment's id and position:

**cURL**

```bash
ITINERARY=$(curl -s https://api.mountaya.com/v1/itineraries/$ITINERARY_ID \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN")

SEGMENT_ID=$(echo "$ITINERARY" | jq -r '.data.segments[0].id')
echo "$ITINERARY" | jq '[.data.segments[] | {id, position, name, mode}]'
```

**TypeScript**

```typescript
const { data: itinerary } = await mountaya.studio.itineraries.getItinerary({
  itinerary_id: itineraryId,
});
const segmentId = itinerary.segments[0]?.id ?? "";

console.log(itinerary.segments.map(({ id, position, name, mode }) => ({ id, position, name, mode })));
```

**Python**

```python
itinerary = requests.get(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
    },
    timeout=30,
).json()["data"]
segment_id = itinerary["segments"][0]["id"]

print([{key: segment[key] for key in ("id", "position", "name", "mode")} for segment in itinerary["segments"]])
```

**Response**

```json
[
  {
    "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    "position": 0,
    "name": "Chamonix to Argentière",
    "mode": "directions"
  }
]
```

Every write to a segment, a waypoint or a group answers this same whole itinerary, so read the new positions from it.

- `segments` is the chain in order, `position` counting from 0. A `directions` segment is routed along the trails between the points its `geojson` MultiPoint names; a `linestring` segment keeps the line as drawn.
- Every write to an itinerary's parts (a segment, a waypoint, a segment group) answers `ItineraryWithDetails`: the itinerary with its `segments`, `waypoints` and `groups`, its totals recomputed. A part a write created is named at `extensions.metadata.created.id` and in the `Location` header.
- Every such write needs the `studio-embedded` scope and a session token minted for `studio-embedded` naming a member with a write role (owner, admin or contributor), and the organization must hold Map Studio (`402` otherwise). A token minted without `user_id`, or for another surface, is a `401`.
- Every such write takes an `Idempotency-Key`. Send the itinerary's `etag` as `If-Match` to land only on the version you read: a stale tag is `412` and nothing is written. Every write to a part moves the itinerary's `etag`, so read it again before the next conditional write.
- A segment, a waypoint or a group another member holds the collaboration lock on is refused with `409` coded `CONFLICT`, the holder at `extensions.metadata.holder.id`.
- The draft changes, not what is published: publish again to show the edit. See [publishing](https://docs.mountaya.com/en/apis/map-studio/publishing.md).

## Insert a segment

`POST` a segment to add it. It joins the end of the chain, or lands before the segment that `before_segment_id` names. This one goes first, so the route starts in Les Houches:

**cURL**

```bash
INSERTED=$(curl -s -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 @- <<JSON
{
  "name": "Les Houches to Chamonix",
  "mode": "directions",
  "before_segment_id": "$SEGMENT_ID",
  "geojson": {"type": "MultiPoint", "coordinates": [[6.7991, 45.8915], [6.8712, 45.9231]]}
}
JSON
)

INSERTED_SEGMENT=$(echo "$INSERTED" | jq -r .extensions.metadata.created.id)
echo "$INSERTED" | jq '[.data.segments[] | {id, position, name}]'
```

**TypeScript**

```typescript
const { data: withInserted, extensions } = await mountaya.studio.itineraries.postItinerarySegment({
  itinerary_id: itineraryId,
  body: {
    name: "Les Houches to Chamonix",
    mode: "directions",
    before_segment_id: segmentId,
    geojson: {
      type: "MultiPoint",
      coordinates: [
        [6.7991, 45.8915],
        [6.8712, 45.9231],
      ],
    },
  },
});
console.log(
  extensions?.metadata?.created?.id,
  withInserted.segments.map(({ id, position, name }) => ({ id, position, name })),
);
```

**Python**

```python
inserted = 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": "Les Houches to Chamonix",
        "mode": "directions",
        "before_segment_id": segment_id,
        "geojson": {"type": "MultiPoint", "coordinates": [[6.7991, 45.8915], [6.8712, 45.9231]]},
    },
    timeout=30,
).json()
inserted_id = inserted["extensions"]["metadata"]["created"]["id"]

print([{key: segment[key] for key in ("id", "position", "name")} for segment in inserted["data"]["segments"]])
```

**Response**

```json
[
  {
    "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
    "position": 0,
    "name": "Les Houches to Chamonix"
  },
  {
    "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    "position": 1,
    "name": "Chamonix to Argentière"
  }
]
```

The neighbours move to meet the new segment, and a routed neighbour is routed again. `extensions.metadata.created.id` names the segment created.

- `POST /v1/itineraries/{itinerary_id}/segments` answers `201`. Body: `name` (2 to 30 characters), `mode` (`directions` or `linestring`), `geojson`, and optionally `before_segment_id`, `color`, `description` (at most 100 characters), `speed` (km/h, 0.01 to 999.99) and `start_at`.
- `directions`: `geojson` is a MultiPoint of 2 to 45 points, and the straight line through them may be at most 100 km. `linestring`: a LineString drawn as given, at most 10,000 positions and 500 km.
- Without `before_segment_id` the segment is appended, and its first position is replaced by the chain's last point. With it, the segment keeps the geometry sent: the segment before it ends on its first point, the segment after it starts on its last point, and each neighbour that moved is recomputed through its own mode. An id that names no segment of this itinerary is a `400` naming `before_segment_id`.
- The create is atomic: points the routing engine cannot route between, in the new segment or a re-routed neighbour, are a `400` naming `geojson`, and nothing is written.
- The new segment joins a group only when both its neighbours belong to the same one.
- `PATCH /v1/itineraries/{itinerary_id}/segments/{segment_id}` merges: a field you leave out keeps its value, and `null` clears a nullable one. A new `geojson` recomputes the segment, and the shared points of its neighbours follow. The mode changes only through `convert`.
- Segment creates, updates, splits, merges and conversions are routed writes, limited together to 120 a minute per member and 1,200 a minute per organization (`429` with `Retry-After`). Their routing is recorded as the organization's `studio-embedded` data usage, never counted toward the Data API's limits, allowance or invoice.

## Split a segment

`split` cuts a segment at a fraction of its length. The first half keeps the segment's id, and the second half is created after it:

**cURL**

```bash
curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments/$SEGMENT_ID/split \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"fraction": 0.5, "first_name": "Chamonix to Les Tines", "second_name": "Les Tines to Argentière"}' \
  | jq '[.data.segments[] | {id, position, name}]'
```

**TypeScript**

```typescript
const { data: split } = await mountaya.studio.itineraries.postItinerarySegmentSplit({
  itinerary_id: itineraryId,
  segment_id: segmentId,
  body: {
    fraction: 0.5,
    first_name: "Chamonix to Les Tines",
    second_name: "Les Tines to Argentière",
  },
});

console.log(split.segments.map(({ id, position, name }) => ({ id, position, name })));
```

**Python**

```python
split = requests.post(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}/segments/{segment_id}/split",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "fraction": 0.5,
        "first_name": "Chamonix to Les Tines",
        "second_name": "Les Tines to Argentière",
    },
    timeout=30,
).json()["data"]

print([{key: segment[key] for key in ("id", "position", "name")} for segment in split["segments"]])
```

**Response**

```json
[
  {
    "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
    "position": 0,
    "name": "Les Houches to Chamonix"
  },
  {
    "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    "position": 1,
    "name": "Chamonix to Les Tines"
  },
  {
    "id": "15a9d3c7-8e02-4b6f-9d41-6f7a2c8e0b53",
    "position": 2,
    "name": "Les Tines to Argentière"
  }
]
```

- `fraction` is in the open interval (0, 1), projected onto the stored line. A split landing within 10 m of either end is a `400`.
- The first half keeps the original's id, description, color, speed and planned start, and its name unless `first_name` renames it. The second half takes the color and speed, and the name unless `second_name` is sent; it starts with no description and no planned start. Both halves keep the original's group.
- In `directions` mode both halves are routed again, so a routing failure aborts the split and writes nothing (`400` naming `geojson`).
- It answers `201`, `extensions.metadata.created.id` naming the second half.
- A `409` with no `extensions.metadata.holder` means the chain changed between your read and the split: read the itinerary again and retry.

## Merge segments

`merge` joins a segment with the one after it, and the result keeps the first one's id. It takes no body:

**cURL**

```bash
curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments/$SEGMENT_ID/merge \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  | jq '[.data.segments[] | {id, position}]'
```

**TypeScript**

```typescript
const { data: merged } = await mountaya.studio.itineraries.postItinerarySegmentMerge({
  itinerary_id: itineraryId,
  segment_id: segmentId,
});

console.log(merged.segments.map(({ id, position }) => ({ id, position })));
```

**Python**

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

print([{key: segment[key] for key in ("id", "position")} for segment in merged["segments"]])
```

**Response**

```json
[
  { "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a", "position": 0 },
  { "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c", "position": 1 }
]
```

Keep the `Idempotency-Key` for a retry: a merge sent twice with a new key merges again.

- The two segments must share a mode and a group. The last segment of a chain, two segments of different modes, or two in different groups is a `409` coded `CONFLICT`, naming no field, until the chain changes.
- In `directions` mode the union of both segments' points is routed again as one route: more than 45 points, more than 100 km in a straight line through them, or points the engine cannot route between is a `400`. In `linestring` mode the two lines are joined and simplified, held to 500 km and 10,000 positions.
- When the two were a group's only members, the group is dissolved.
- Answers `200` with the whole itinerary.

## Switch between routed and drawn

`convert` turns a routed segment into a drawn line, or a drawn line into a route along the trails. The segment keeps its ends, so its neighbours do not move:

**cURL**

```bash
curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments/$SEGMENT_ID/convert \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"mode": "linestring"}' \
  | jq '[.data.segments[] | {id, mode}]'
```

**TypeScript**

```typescript
const { data: converted } = await mountaya.studio.itineraries.postItinerarySegmentConvert({
  itinerary_id: itineraryId,
  segment_id: segmentId,
  body: { mode: "linestring" },
});

console.log(converted.segments.map(({ id, mode }) => ({ id, mode })));
```

**Python**

```python
converted = requests.post(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}/segments/{segment_id}/convert",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={"mode": "linestring"},
    timeout=30,
).json()["data"]

print([{key: segment[key] for key in ("id", "mode")} for segment in converted["segments"]])
```

**Response**

```json
[
  { "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a", "mode": "directions" },
  { "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c", "mode": "linestring" }
]
```

- `directions` to `linestring` keeps the routed line as the drawn one, simplified, and clears the turn-by-turn steps.
- `linestring` to `directions` routes through the segment's stored points, or through a simplification of the drawn line when it has none, at most 45 and keeping both ends exactly. A routing failure writes nothing (`400` naming `geojson`), and the routed segment is held to 100 km in a straight line through its points.
- Sending the mode the segment already has changes nothing and answers `200`.

## Group segments

A group gives a run of consecutive segments one name and color, on the elevation profile and in the segment list. The segments themselves do not change. This one groups the first two:

**cURL**

```bash
curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segment-groups \
  -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\": \"Day 1\", \"color\": \"#2f80ed\", \"segment_ids\": [\"$INSERTED_SEGMENT\", \"$SEGMENT_ID\"]}" \
  | jq '{groups: [.data.groups[] | {id, name}], segments: [.data.segments[] | {id, group_id}]}'
```

**TypeScript**

```typescript
const { data: chain } = await mountaya.studio.itineraries.getItinerary({
  itinerary_id: itineraryId,
});
const segmentIds = chain.segments.slice(0, 2).map(({ id }) => id);

const { data: grouped } = await mountaya.studio.itineraries.postItinerarySegmentGroup({
  itinerary_id: itineraryId,
  body: { name: "Day 1", color: "#2f80ed", segment_ids: segmentIds },
});

console.log(grouped.groups.map(({ id, name }) => ({ id, name })));
```

**Python**

```python
grouped = requests.post(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}/segment-groups",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={"name": "Day 1", "color": "#2f80ed", "segment_ids": [inserted_id, segment_id]},
    timeout=30,
).json()["data"]

print([{key: group[key] for key in ("id", "name")} for group in grouped["groups"]])
```

**Response**

```json
{
  "groups": [
    { "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23", "name": "Day 1" }
  ],
  "segments": [
    { "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a", "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23" },
    { "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c", "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23" }
  ]
}
```

- `POST /v1/itineraries/{itinerary_id}/segment-groups` answers `201`. Body: `name` (2 to 30 characters), `color` (required), `segment_ids` (at least two, consecutive in the chain, in any order) and optionally `speed`, which overrides the run's displayed duration.
- Segments that are not consecutive, fewer than two, or not of this itinerary are a `400`. A segment already in another group is a `409` coded `CONFLICT`, one entry per such segment naming its position in `segment_ids`.
- `PATCH /v1/itineraries/{itinerary_id}/segment-groups/{group_id}` changes the name, color, speed or membership; `segment_ids`, when sent, is the whole new membership, and a segment dropped from it is ungrouped. `DELETE` on the same path dissolves the group and leaves its segments in place.
- A group never touches its segments' geometry, totals or positions.

## Mark a place with a waypoint

A waypoint marks a place along the route: a hut, a water point, a cut-off. Its `position` orders it among the others:

**cURL**

```bash
curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/waypoints \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"mode": "poi", "name": "Chamonix", "icon": "droplet", "position": 0, "amenities": ["water"], "geojson": {"type": "Point", "coordinates": [6.8712, 45.9231]}}' \
  | jq '[.data.waypoints[] | {id, position, name, icon}]'
```

**TypeScript**

```typescript
const { data: marked } = await mountaya.studio.itineraries.postItineraryWaypoint({
  itinerary_id: itineraryId,
  body: {
    mode: "poi",
    name: "Chamonix",
    icon: "droplet",
    position: 0,
    amenities: ["water"],
    geojson: { type: "Point", coordinates: [6.8712, 45.9231] },
  },
});

console.log(marked.waypoints.map(({ id, position, name, icon }) => ({ id, position, name, icon })));
```

**Python**

```python
marked = requests.post(
    f"https://api.mountaya.com/v1/itineraries/{itinerary_id}/waypoints",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "mode": "poi",
        "name": "Chamonix",
        "icon": "droplet",
        "position": 0,
        "amenities": ["water"],
        "geojson": {"type": "Point", "coordinates": [6.8712, 45.9231]},
    },
    timeout=30,
).json()["data"]

print([{key: waypoint[key] for key in ("id", "position", "name", "icon")} for waypoint in marked["waypoints"]])
```

**Response**

```json
[
  {
    "id": "a142860b-7c91-4c27-9389-c12aa0cfec2e",
    "position": 0,
    "name": "Chamonix",
    "icon": "droplet"
  }
]
```

`PATCH` a waypoint to add services or a cut-off, as the [race course tutorial](https://docs.mountaya.com/en/sdks/typescript/tutorials/race-course.md) does.

- `POST /v1/itineraries/{itinerary_id}/waypoints` answers `201`. `mode`, `position` (0 to 9,999) and `geojson` (a bare Point) are required. A `poi` also needs `name` (2 to 30 characters) and `icon`; a `point` may carry neither.
- `icon` is one of a closed set (`hut`, `droplet`, `flag`, `medical-cross`, `cable-car`, `camping` and more: see the [reference](https://docs.mountaya.com/en/apis/map-studio/reference/waypoints.md)). `flag-start` and `flag-end` are refused on every write.
- `position` is stored as sent: no other waypoint moves to make room, and deleting one renumbers nothing.
- Optional: `amenities` (a closed vocabulary such as `water`, `food`, `first-aid`, `toilets`), `color`, `contact`, `description` (at most 100 characters), `media`, `properties` (at most 20 fields of your own) and `timing` (`cutoff_at`, `stop_duration` in seconds).
- `PATCH /v1/itineraries/{itinerary_id}/waypoints/{waypoint_id}` merges: a field you leave out keeps its value, and a `contact`, `media`, `properties` or `timing` you send replaces the stored one whole. `DELETE` on the same path removes the waypoint.

## Remove a segment

Only the first or the last segment of a chain can be deleted, with `DELETE` on its path. Removing one in the middle would break the chain, so the API refuses it with a `409`.

- `DELETE /v1/itineraries/{itinerary_id}/segments/{segment_id}` answers `200` with the whole itinerary, the chain renumbered. An interior segment is a `409` coded `CONFLICT` until the chain changes: merge it into a neighbour first.
- Deleting an end recomputes nothing. When the deleted segment was one of a group's only two members, the group is dissolved.
- The published version keeps the segment until you publish again.

## Next steps

- [Publishing](https://docs.mountaya.com/en/apis/map-studio/publishing.md): Show your edits to the public.
- [Segments reference](https://docs.mountaya.com/en/apis/map-studio/reference/segments.md): Every field and refusal of a segment write.
