# Segments

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

The ordered legs a route is made of.

 A segment is routed along real trails or drawn freehand, and the operations here are the ones that change the shape of a route: insert, split, merge, reorder, and switch a leg between routed and freehand.

## Create a segment, at the end of the chain or before another

### POST /v1/itineraries/{itinerary_id}/segments

- Operation: `postItinerarySegment`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: answers within 30000 ms or times out

Creates a new segment within the itinerary, at the end of its chain or anywhere before it, and renumbers the chain.

Without `before_segment_id`, the segment is appended to the end of the chain, and it starts where the chain ends: on an itinerary that already has segments, the first position of `geojson` is replaced with the last point of the current last segment before the 100 km limit is checked.

With `before_segment_id`, the segment is inserted ahead of that one, so the first segment's identifier inserts at the head of the chain, and every segment from that one on moves down a `position`. The new segment keeps the geometry sent, and its neighbours move to meet it: the segment before it has its last point moved onto the new segment's first point, and the segment it is inserted before has its first point moved onto the new segment's last point. Each neighbour that moved is recomputed through its own mode, a `directions` neighbour being re-routed. An identifier that names no segment of this itinerary's chain is a 400 naming `before_segment_id`.

A routed segment, appended, inserted or a neighbour re-routed, is pinned onto the junctions it meets: the route the engine returns is joined to each junction it does not reach, one off the routable network, by a short straight connector. So a `directions` segment starts where the chain ends and stays exactly connected to its neighbours, as a `linestring` one does.

The create is atomic: if any of its routing fails, the request fails and the itinerary is left exactly as it was. Waypoints the routing engine cannot route between, one away from any routable way or two with no connection between them, in the new segment or in a re-routed neighbour, are a 400 naming `geojson`.

The new segment joins a group only when BOTH of its neighbours already belong to the same one. A segment appended at the end, or inserted at the head, has only one neighbour and joins none, since joining would silently extend the group's boundary.

Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does: a create can renumber every following position and rewrite up to two neighbours, which one segment would not show. `Location` and `extensions.metadata.created.id` name the segment created.

Send the itinerary's `ETag` as `If-Match` to make the create conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is created.

Segment creates are routed writes, limited together with every other routed segment write (split, merge, convert and update) to 120 requests a minute per user and 1200 a minute per organization; past either, the request is refused with **429** and `Retry-After`. The routing they do is recorded as the organization's `studio-embedded` data usage, which `getOrganizationUsageData` reports and which never counts toward the Data API's per-minute limit, monthly allowance or invoice.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment.created`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-created), [`itinerary.segment.updated`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-updated), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the tasks `itinerary.segment.create`, `itinerary.segment.insert`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The new segment: its mode, its color, and either the positions to route between or the geometry to draw freehand, and, to place it anywhere but the end of the chain, `before_segment_id`, the segment it goes ahead of. The server assigns the position; a field the body does not declare, such as `position`, is a `400` naming it.

- `before_segment_id` (string (uuid), in body, optional): Identifier of the segment the new one is inserted BEFORE, so the first segment's identifier inserts at the head of the chain. Optional and not nullable: omit it to append the new segment to the end of the chain.

  An identifier that names no segment of this itinerary's chain, one of another itinerary or one already deleted included, is a 400 naming `before_segment_id` rather than a 404.

- `color` (string, in body, optional): Hex color code for rendering this segment on the map. Both the three-digit and the six-digit forms are accepted, in either case, and either is stored as six lowercase digits (`#F60` and `#FF6600` both as `#ff6600`), which is the form every read returns.

  Optional and not nullable: omit it to use the default activity color. The update operation types the same field nullable, because there `null` returns a segment to that default.

- `description` (string, in body, optional): Free-text description of the segment, at most 100 characters as sent, leading and trailing whitespace included; that whitespace is then trimmed. Omit it, or send one that trims to nothing, to create the segment without one.

- `geojson` (GeoJSONPoint | GeoJSONMultiPoint | GeoJSONLineString | GeoJSONMultiLineString | GeoJSONPolygon | GeoJSONMultiPolygon | GeoJSONGeometryCollection, in body, required): The segment's path, as `mode` reads it. In `directions` mode it is a MultiPoint of 2 to 45 waypoints the route passes through in order, and the straight line through them must not exceed 100 km; what is stored is the route computed between them. The MultiPoint is sent bare or inside a GeometryCollection, the shape a `directions` segment is read in, and only the collection's MultiPoint is read: a LineString beside it is ignored.

  In `linestring` mode it is the LineString drawn, kept as drawn rather than routed: the server simplifies it to a 3 m tolerance to remove GPS jitter, resamples it to about one point every 50 m carrying each point's elevation, and, when that adds points and the vertices drawn number fewer than the line's sample budget `ItinerarySegment.geojson` states, stores those vertices beside it as a MultiPoint in a GeometryCollection. Any other line, a dense recorded track among them, is stored as the bare resampled LineString. The LineString is sent bare or inside a GeometryCollection. When that collection also holds a MultiPoint, the MultiPoint is read as the vertices drawn: the path is measured, resampled and analysed from it, and the LineString only has to hold two positions. A `linestring` segment read with its drawn vertices therefore changes path through its MultiPoint, or through a bare LineString sent in its place, never through the LineString beside it.

  Appended to an itinerary that already has segments, the first position is replaced with the last point of the current last segment, so the new segment starts where the chain ends, and the 100 km limit is checked after that replacement. Inserted with `before_segment_id`, the ends are kept where they were sent: the neighbouring segments move to meet this one. A `directions` segment is pinned onto every junction it shares with a neighbour, a short straight connector joining the route to one off the routable network, so it stays exactly connected to the chain.

  The geometry holds at most 10,000 positions as sent. In `linestring` mode they are counted across every member of a collection. In `directions` mode only the MultiPoint read is counted: a LineString beside it, the routed line a `directions` segment is read with included, is not, whatever its length, and only the 32 MiB a JSON body may weigh bounds it. A `linestring` path measures at most 500 km. Either one past its ceiling is a 400 naming `geojson`.

  Every position is `[longitude, latitude]`, with an optional altitude in meters. A position `mode` reads (in `linestring` mode every position of every member, in `directions` mode the MultiPoint's alone) outside the longitude and latitude ranges is a 400 naming it, and so is one of more than three numbers when every position carries the same count. The name runs through the member holding the position: `geojson.coordinates[0]` for the first position of a bare geometry, `geojson.geometries[1].coordinates[0]` for the first waypoint of a `directions` segment sent back as read. A LineString beside a `directions` MultiPoint is ignored, its positions included. Positions whose counts differ, and a position of fewer than two numbers, are refused in any member, that LineString included, as a 400 naming `geojson`.

- `mode` (string, in body, required, one of: `directions`, `linestring`): How the segment's path is defined, which decides what `geojson` must carry: `directions` routes between the waypoints of a MultiPoint, `linestring` keeps the drawn line rather than routing it.

- `name` (string, in body, required): Display name of the segment, 2 to 30 characters as sent. Leading and trailing whitespace is then trimmed, and what remains must still be at least 2 characters. A name is one line: a tab, a line break or a line separator between two of its characters is a `400`, and one at either end is trimmed with the whitespace there.

- `speed` (number (double), in body, optional): Travel speed in km/h used to compute the segment duration. At least 0.01 and at most 999.99, and stored rounded to two decimal places.

  Optional and not nullable: omit it to use the default activity speed. The update operation types the same field nullable, because there `null` returns a segment to that default.

  A speed at which the segment would take longer than 99,999,999 seconds, a long freehand line drawn at a crawl, is a `400` naming `speed`.

- `start_at` (string (date-time), in body, optional): Planned start date and time for this segment.

  Optional and not nullable: omit it to create the segment without one. The update operation types the same field nullable, because there `null` clears it.

**Response** `201`

The whole itinerary after the create, with the new segment in its place and the chain renumbered around it. `Location` names the new segment, `/v1/itineraries/{itinerary_id}/segments/{segment_id}`, and `extensions.metadata.created.id` is its identifier. `ETag` carries the itinerary's new version.

- `extensions` (object, required): The envelope's second half, everything the answer carries that is not the answer itself. Here that is `metadata.created`, the segment this request created.
  - `metadata` (ResponseMetadataCreatedPart, required): What a write that created a part of an itinerary created, at `extensions.metadata` of its `201`. The answer's `data` is the whole itinerary, as every write to one answers it, so this is how a client finds the part it just made without searching for it; `Location` names the same part.
    - `created` (object, required): The part created.
      - `id` (string (uuid), required): Identifier of the segment, segment group or waypoint created. On a split, the second of the two segments, the one the split made.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `Location`: The path of what the request created, relative to this host. A part of an itinerary is addressed under its itinerary, so a new segment's is `/v1/itineraries/{itinerary_id}/segments/{segment_id}`.
- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: No itinerary with that identifier is reachable: either none exists, or this credential cannot view it. The two answer alike, so this status cannot be used to learn which itinerary ids exist. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does. A `before_segment_id` that names no segment of this itinerary is a `400` naming that field, not a `404`.
- `409`: Conflict, from either of two causes, both met only by a request that sends `before_segment_id`: an append holds no lock and contends with neither. Both carry `extensions.code` `CONFLICT`, so what tells them apart is `extensions.metadata`. Present, carrying a holder: another member of the collaboration session holds the edit lock on one of the neighbouring segments the insert has to rewrite. The holder is at `extensions.metadata.holder.id`. A body this operation refuses is answered with its `400` before any lock is looked at, so a peer's lock is reported only for a request that is otherwise well formed. Absent: the chain, or a segment this insert was computed from, changed between the read it was planned against and the write: another writer reordered the chain, or changed a neighbour the insert rewrites, by a peer's edit, a segment inserted beside it or a neighbour's drag. Nothing is created; retry against a fresh read. Nothing holds a lock, so there is no holder to name and `extensions` is not required. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Keep the Idempotency-Key and send it again on a retry: a create whose answer
# was lost is then answered with the first one's 201 rather than run twice.
curl -s https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Day 1: Col de Voza",
    "mode": "directions",
    "color": "#2f80ed",
    "geojson": {
      "type": "MultiPoint",
      "coordinates": [[6.7994, 45.8905], [6.7612, 45.8479]]
    }
  }'
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.postItinerarySegment({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  body: {
    name: "Day 1: Col de Voza",
    mode: "directions",
    color: "#2f80ed",
    geojson: {
      type: "MultiPoint",
      coordinates: [[6.7994, 45.8905], [6.7612, 45.8479]],
    },
  },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.post(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "name": "Day 1: Col de Voza",
        "mode": "directions",
        "color": "#2f80ed",
        "geojson": {
            "type": "MultiPoint",
            "coordinates": [[6.7994, 45.8905], [6.7612, 45.8479]],
        },
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

**cURL: Insert a segment mid-chain**

```bash
# `before_segment_id` names where it lands. The whole chain is renumbered, so read
# positions back rather than computing them.
curl -s https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "before_segment_id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    "name": "Approach from the valley",
    "mode": "directions",
    "speed": 4,
    "geojson": {
      "type": "MultiPoint",
      "coordinates": [[6.8694, 45.9237], [6.8412, 45.9105], [6.7986, 45.8918]]
    }
  }'
```

Response 201:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  },
  "extensions": {
    "metadata": {
      "created": {
        "id": "2c8e5f13-7a94-4b06-8d21-9e3f0a6c7b58"
      }
    }
  }
}
```

## Update an existing segment

### PATCH /v1/itineraries/{itinerary_id}/segments/{segment_id}

- Operation: `patchItinerarySegment`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Updates an existing segment within the itinerary. Every field is optional: an omitted field keeps its current value, and `null` clears a nullable one. A new `geojson` re-derives the segment's geometry and totals, and the shared points of the neighbouring segments follow it. The segment's mode is changed by its own operation, `postItinerarySegmentConvert`.

Waypoints the routing engine cannot route between, in this segment in `directions` mode or in a `directions` neighbour the update re-routes, are a 400 naming `geojson`, and nothing is written.

Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does: a new `geojson` moves the shared points of the neighbours, and the itinerary's totals follow the segment's.

Send the itinerary's `ETag` as `If-Match` to make the update conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is changed.

Segment updates are routed writes, limited together with every other routed segment write (create, split, merge and convert) to 120 requests a minute per user and 1200 a minute per organization; past either, the request is refused with **429** and `Retry-After`. The routing they do is recorded as the organization's `studio-embedded` data usage, which `getOrganizationUsageData` reports and which never counts toward the Data API's per-minute limit, monthly allowance or invoice.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment.updated`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-updated), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment.update`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

- `segment_id` (string (uuid), in path, required): Identifier of the segment within the itinerary named by `itinerary_id`. A segment belonging to another itinerary is a 404, not a 403.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The fields to change. A field you omit keeps its stored value, and a nullable field sent as `null` is cleared. A field the body does not declare, such as `mode` or `position`, is a `400` naming it: the mode has its own operation, and the position is the chain's to assign.

- `color` (string | null, in body, optional): Hex color code for rendering this segment on the map. Both the three-digit and the six-digit forms are accepted, in either case, and either is stored as six lowercase digits (`#F60` and `#FF6600` both as `#ff6600`), which is the form every read returns. Omit to keep the current value; `null` returns the segment to the default activity color.

- `description` (string | null, in body, optional): Free-text description of the segment, at most 100 characters as sent, leading and trailing whitespace included; that whitespace is then trimmed. Omit to keep the current value; `null`, or a value that trims to nothing, clears it.

- `geojson` (GeoJSONPoint | GeoJSONMultiPoint | GeoJSONLineString | GeoJSONMultiLineString | GeoJSONPolygon | GeoJSONMultiPolygon | GeoJSONGeometryCollection, in body, optional): GeoJSON Geometry representing the segment path, read as the segment's mode reads it on creation. In directions mode it is a MultiPoint of 2 to 45 waypoints (inclusive), sent bare or inside a GeometryCollection whose MultiPoint alone is read, and the straight line through them must not exceed 100 km. In linestring mode it is a LineString, sent bare or inside a GeometryCollection, kept as drawn rather than routed and simplified and resampled as it is on creation. When that collection also holds a MultiPoint, the MultiPoint is read as the vertices drawn and the LineString only has to hold two positions, so a segment read with its drawn vertices changes path through its MultiPoint, or through a bare LineString sent in its place. Either way the segment's `geojson` as read is accepted back unchanged.

  The geometry holds at most 10,000 positions as sent. In linestring mode they are counted across every member of a collection. In directions mode only the MultiPoint read is counted: the routed LineString a directions segment is read with is not, whatever its length, so it is accepted back beside its MultiPoint, bounded only by the 32 MiB a JSON body may weigh. A linestring path measures at most 500 km. Either one past its ceiling is a 400 naming `geojson`.

  A position the segment's mode reads (in linestring mode every position of every member, in directions mode the MultiPoint's alone) outside the longitude and latitude ranges is a 400 naming it, and so is one of more than three numbers when every position carries the same count. The name runs through the member holding the position: `geojson.coordinates[0]` for the first position of a bare geometry, `geojson.geometries[1].coordinates[0]` for the first waypoint of a directions segment sent back as read. The routed LineString beside a directions MultiPoint is ignored, its positions included. Positions whose counts differ, and a position of fewer than two numbers, are refused in any member, that LineString included, as a 400 naming `geojson`.

  Optional and not nullable, unlike every other field on this operation: omit it to leave the stored geometry untouched. There is no way to clear a segment's geometry through this operation, because a segment without geometry cannot be routed or measured, so a `null` is a 400.

- `name` (string, in body, optional): Display name of the segment. Omit to keep the current value. 2 to 30 characters as sent; leading and trailing whitespace is then trimmed, and what remains must still be at least 2 characters. A name is one line: a tab, a line break or a line separator between two of its characters is a `400`, and one at either end is trimmed with the whitespace there.

- `speed` (number (double) | null, in body, optional): Travel speed in km/h used to compute the segment duration. Omit to keep the current value; `null` returns the segment to the default activity speed. At least 0.01 and at most 999.99, and stored rounded to two decimal places.

  A speed at which the segment would take longer than 99,999,999 seconds, a long freehand line drawn at a crawl, is a `400` naming `speed`.

- `start_at` (string (date-time) | null, in body, optional): Planned start date and time for this segment. Omit to keep the current value; `null` clears it.

**Response** `200`

The whole itinerary after the update, with the segment's geometry and totals recomputed, and its new `ETag`.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Either no itinerary with that identifier is reachable, because none exists or this credential cannot view it, or that itinerary holds no segment with the identifier given. A segment that belongs to another itinerary answers the same way as one that does not exist, so neither identifier can be probed here. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does.
- `409`: Conflict, from either of two causes. Both carry `extensions.code` `CONFLICT`, so what tells them apart is `extensions.metadata`. Present, carrying a holder: another member of the collaboration session holds the edit lock on the segment, or on a neighbouring segment whose shared point this update moves and so rewrites. The holder is at `extensions.metadata.holder.id`. A body this operation refuses is answered with its `400` before any lock is looked at, so a peer's lock is reported only for a request that is otherwise well formed. Absent: a segment this update was computed from changed between the read it was planned against and the write. Another writer removed the segment, or a neighbour whose shared point this update moves, by a delete or a merge, or changed one of them, by a peer's edit, a segment inserted beside it or a neighbour's drag. Nothing is written; retry against a fresh read. A reordering of the chain alone does not refuse this update. Nothing holds a lock, so there is no holder to name and `extensions` is not required. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# PATCH merges: a field you omit keeps its stored value, and `null` clears a
# nullable one. Send only what changes.
curl -s -X PATCH https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Day 1: Bionnassay",
    "description": "Shortened to finish at the Bionnassay hut.",
    "color": "#eb5757",
    "speed": 4.2,
    "start_at": "2026-07-04T08:00:00Z"
  }'
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.patchItinerarySegment({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  segment_id: "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
  body: {
    name: "Day 1: Bionnassay",
    description: "Shortened to finish at the Bionnassay hut.",
    color: "#eb5757",
    speed: 4.2,
    start_at: new Date("2026-07-04T08:00:00Z"),
  },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.patch(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "name": "Day 1: Bionnassay",
        "description": "Shortened to finish at the Bionnassay hut.",
        "color": "#eb5757",
        "speed": 4.2,
        "start_at": "2026-07-04T08:00:00Z",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  }
}
```

## Delete a segment from an itinerary

### DELETE /v1/itineraries/{itinerary_id}/segments/{segment_id}

- Operation: `deleteItinerarySegment`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Permanently deletes the segment. This action cannot be undone.

An itinerary's segments form a chain, each one starting where the previous ends, so only a segment at an END of that chain may be deleted: the first, the last, or (on a single-segment itinerary) the one that is both. Removing an interior segment would leave the two it sat between disconnected, and is refused with a `409` whose `extensions.code` is `CONFLICT`: the chain's shape forbids it, and the same request is refused the same way until the chain changes.

Deleting an end is otherwise lossless: the remaining segments keep their order and their geometry is not recomputed, because a promoted first segment has no predecessor to meet. The one exception is grouping: when the deleted segment was one of a group's only two members, the group is dissolved and the member left behind is un-grouped, since a group never covers fewer than two segments.

Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does, so the client sees the chain renumbered and any group dissolved.

Send the itinerary's `ETag` as `If-Match` to make the delete conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is deleted.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-deleted), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment.delete`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

- `segment_id` (string (uuid), in path, required): Identifier of the segment within the itinerary named by `itinerary_id`. A segment belonging to another itinerary is a 404, not a 403.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200`

The whole itinerary after the delete, the remaining segments renumbered, and its new `ETag`.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Either no itinerary with that identifier is reachable, because none exists or this credential cannot view it, or that itinerary holds no segment with the identifier given. A segment that belongs to another itinerary answers the same way as one that does not exist, so neither identifier can be probed here. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does. A second delete of the same segment answers here too: send a retried delete with the same `Idempotency-Key` and it is answered with the first one's 200.
- `409`: Conflict, from either of two causes, each carrying `extensions.code` `CONFLICT`. Carrying a holder: another member of the collaboration session holds the edit lock on the segment. The holder is at `extensions.metadata.holder.id`. Carrying no metadata: the segment is an interior one, which only an end of the chain may be: deleting it would leave the two it sits between disconnected. Nothing is deleted, and the same request is refused the same way until the chain changes; delete from an end, or merge the segment into its neighbour instead. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Deleting renumbers the chain so positions stay consecutive from zero.
curl -s -X DELETE https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.deleteItinerarySegment({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  segment_id: "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.delete(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  }
}
```

## Merge a segment with the one that follows it

### POST /v1/itineraries/{itinerary_id}/segments/{segment_id}/merge

- Operation: `postItinerarySegmentMerge`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: answers within 30000 ms or times out

Fuses the segment into a single segment together with the next one in the chain, and renumbers the chain. The direction is fixed and takes no parameter: on an ordered chain, merging segment i with i-1 is the same operation as merging i-1 with its next, so a direction field would only add a redundant way to express the same request. The merged result keeps the identifier of the lower-positioned of the two.

In directions mode the union of both segments' waypoints is re-routed as one request. The two existing geometries are never simply joined end to end: the junction may have been snapped, so the joined line would be a path routing would never return, leaving distance, duration and steps inconsistent with the geometry. In linestring mode the two stored lines are joined end to end, and the joined line is simplified, resampled and analysed as a newly drawn line is. The 3 m simplification removes the positions resampling added, and with them any vertex drawn that lies within 3 m of the straight line between the vertices kept on either side of it, the point where the two lines met included. The MultiPoint of vertices drawn that either segment's `geojson` carries is not read: the merged segment's vertices drawn are those of the joined line that the simplification keeps.

Refused with 409, its entry coded `CONFLICT` and naming no field, when the chain does not allow the merge as it stands: the segment is the last of the chain, so there is no next segment to fuse with, or the two segments use different modes, or they belong to different groups. The same request is refused the same way until the chain changes. Refused with 400 when their combined waypoint count exceeds the directions limit of 45. The limit is checked before the routing call, and the error states the 45-waypoint limit. In directions mode the merged segment is held to the 100 km every routed segment is, measured along the straight line through its waypoints, so two segments that together exceed it are refused with 400 too, and waypoints the routing engine cannot route between are a 400 naming `geojson`, the merged segment's geometry, although a merge takes no body. In linestring mode the joined line is held to the 500 km every freehand segment is, measured as its stored distance is, so two lines that together measure more are refused with 400 naming `geojson` in the same way, and nothing is merged. When the vertices the simplification keeps of the joined line number more than the 10,000 positions a segment's `geojson` may carry, the merge is refused with 400, naming no field, before anything is analysed, and nothing is merged; the error states the 10,000-position limit.

Takes no request body. Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does: a merge renumbers every following position and can change group membership. When the two segments were a group's only two members, the group is dissolved and the merged segment un-grouped, since a group never covers fewer than two segments.

Not safe to repeat blindly: sent twice, it merges the merged segment with the one after it in turn. Send an `Idempotency-Key` and repeat it on a retry, which is then answered with the first attempt's outcome. Send the itinerary's `ETag` as `If-Match` to make the merge conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is merged.

Merges are routed writes, limited together with every other routed segment write (create, split, convert and update) to 120 requests a minute per user and 1200 a minute per organization; past either, the request is refused with **429** and `Retry-After`. The routing they do is recorded as the organization's `studio-embedded` data usage, which `getOrganizationUsageData` reports and which never counts toward the Data API's per-minute limit, monthly allowance or invoice.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment.merged`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-merged), [`itinerary.segment.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-deleted), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment.merge`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

- `segment_id` (string (uuid), in path, required): Identifier of the segment within the itinerary named by `itinerary_id`. A segment belonging to another itinerary is a 404, not a 403.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200`

The whole itinerary after the merge: the two segments are one, carrying the lower-positioned segment's identifier, and the ordering after them has closed up. `ETag` carries the itinerary's new version.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Either no itinerary with that identifier is reachable, because none exists or this credential cannot view it, or that itinerary holds no segment with the identifier given. A segment that belongs to another itinerary answers the same way as one that does not exist, so neither identifier can be probed here. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does.
- `409`: Conflict, from one of three causes. Each carries `extensions.code` `CONFLICT`; `extensions.metadata` names a holder on the first alone. Carrying a holder: another member of the collaboration session holds the edit lock on one of the two segments. The holder is at `extensions.metadata.holder.id`. The chain does not allow the merge as it stands: the segment is the last of the chain, with no next segment to fuse with, or the two segments use different modes, or they belong to different groups. The entry names no field, nothing is merged, and the same request is refused the same way until the chain changes: convert one of the two, or regroup them, first. The chain, or a segment this merge was computed from, changed between the read it was planned against and the write: another writer reordered the chain, or changed one of the two segments or a neighbour, by a peer's edit, a segment inserted beside them or a neighbour's drag. Nothing is merged; retry against a fresh read. Nothing holds a lock, so there is no holder to name and `extensions` is not required. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Merges this segment with the next one in the chain. The merged segment keeps this
# segment's identifier; the next one disappears.
curl -s -X POST https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c/merge \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.postItinerarySegmentMerge({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  segment_id: "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.post(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c/merge",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  }
}
```

## Convert a segment between routed and freehand

### POST /v1/itineraries/{itinerary_id}/segments/{segment_id}/convert

- Operation: `postItinerarySegmentConvert`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Converts the segment to the mode the body names, routed (`directions`) or freehand (`linestring`), and re-derives its geometry accordingly. This is its own operation rather than a field on `patchItinerarySegment` because it can fail routing where a metadata update cannot, and giving it a dedicated operation leaves exactly one way to change a segment's engine.

directions to linestring keeps the routed line as the freehand line, simplified and resampled as a line drawn on creation is (`SegmentCreateParams.geojson`), and clears the turn-by-turn steps, which describe nothing a freehand line carries. A routed line of more positions than the 10,000 a segment write takes, if the simplification leaves it past them, is simplified further at a coarser tolerance until it fits them, keeping both its ends, so the freehand segment, like every segment, is accepted back as read.

linestring to directions derives the waypoints to route through, using the segment's stored waypoints when it has them and otherwise a simplification of the drawn line, tightened until it fits within the directions limit of 45. It preserves the original endpoints exactly, and the routed segment is held to the 100 km every routed segment is, measured along the straight line through those waypoints. A routing failure aborts the change and writes nothing: waypoints the routing engine cannot route between are a 400 naming `geojson`, the segment's geometry.

The mode is a state the segment is set to, so the request is safe to repeat: sending the mode the segment already has changes nothing and answers 200 with the itinerary.

Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does: the answer carries the itinerary's recomputed totals beside the segment. Neither neighbour changes, since both directions keep the segment's endpoints where they are.

Send the itinerary's `ETag` as `If-Match` to make the conversion conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is changed.

Conversions are routed writes, limited together with every other routed segment write (create, split, merge and update) to 120 requests a minute per user and 1200 a minute per organization; past either, the request is refused with **429** and `Retry-After`. The routing they do is recorded as the organization's `studio-embedded` data usage, which `getOrganizationUsageData` reports and which never counts toward the Data API's per-minute limit, monthly allowance or invoice.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment.converted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-converted), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment.convert`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

- `segment_id` (string (uuid), in path, required): Identifier of the segment within the itinerary named by `itinerary_id`. A segment belonging to another itinerary is a 404, not a 403.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The mode to convert the segment to. Converting between routed and freehand recomputes or discards the routed geometry accordingly.

- `mode` (string, in body, required, one of: `directions`, `linestring`): How the segment's path is defined, which decides what `geojson` must carry: `directions` routes between the waypoints of a MultiPoint, `linestring` keeps the drawn line rather than routing it.

**Response** `200`

The whole itinerary after the conversion, because converting between routed and freehand recomputes the segment's geometry and the totals that depend on it. `ETag` carries the itinerary's new version.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Either no itinerary with that identifier is reachable, because none exists or this credential cannot view it, or that itinerary holds no segment with the identifier given. A segment that belongs to another itinerary answers the same way as one that does not exist, so neither identifier can be probed here. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does.
- `409`: Conflict, from either of two causes. Both carry `extensions.code` `CONFLICT`, so what tells them apart is `extensions.metadata`. Present, carrying a holder: another member of the collaboration session holds the edit lock on the segment. The holder is at `extensions.metadata.holder.id`. A body this operation refuses is answered with its `400` before any lock is looked at, so a peer's lock is reported only for a request that is otherwise well formed. Absent: a segment this change was computed from changed between the read it was planned against and the write. Another writer removed the segment, by a delete or a merge, or changed it or a neighbour this change rewrites, by a peer's edit, a segment inserted beside it or a neighbour's drag. The mode is unchanged; retry against a fresh read. A reordering of the chain alone does not refuse this change. Nothing holds a lock, so there is no holder to name and `extensions` is not required. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Changing mode re-interprets the stored geometry: `directions` routes between its
# points, `linestring` keeps the drawn line.
curl -s -X POST https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c/convert \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "directions"
  }'
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.postItinerarySegmentConvert({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  segment_id: "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
  body: { mode: "directions" },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.post(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c/convert",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={"mode": "directions"},
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  }
}
```

## Split a segment in two at a fraction of its length

### POST /v1/itineraries/{itinerary_id}/segments/{segment_id}/split

- Operation: `postItinerarySegmentSplit`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: answers within 30000 ms or times out

Cuts the segment into two consecutive segments at the given fraction of its length, and renumbers the chain. The first half keeps the original identifier; the second is created after it. Both halves inherit the original segment's group, so a split never breaks a group's contiguity.

The first half keeps the original's description, color, speed and planned start, and its name unless `first_name` renames it. The second half takes the original's color and speed, and its name unless `second_name` is sent; it starts with no description and no planned start, since both describe the original as a whole.

The fraction is projected server-side onto the stored geometry and inserted as the first half's last vertex and the second half's first vertex, so the two halves stay exactly connected and no neighbour recompute is triggered. Both halves also take that junction as a waypoint. In directions mode BOTH halves are re-routed (a sub-path of a route is not, in general, the route of a sub-path), so a routing failure aborts the split and writes nothing: waypoints the routing engine cannot route between, in either half, are a 400 naming `geojson`, the segment's geometry.

Refused with 400 when the projected point lands within 10 m of either endpoint, since a small fraction is degenerate on a short segment.

A split creates a segment, the second half, so it answers `201`: the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does, since a split renumbers every following position. `Location` and `extensions.metadata.created.id` name the second half; the first keeps the identifier in the path.

Send the itinerary's `ETag` as `If-Match` to make the split conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is split.

Splits are routed writes, limited together with every other routed segment write (create, merge, convert and update) to 120 requests a minute per user and 1200 a minute per organization; past either, the request is refused with **429** and `Retry-After`. The routing they do is recorded as the organization's `studio-embedded` data usage, which `getOrganizationUsageData` reports and which never counts toward the Data API's per-minute limit, monthly allowance or invoice.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment.split`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-split), [`itinerary.segment.created`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment.md#itinerary-segment-created), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment.split`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

- `segment_id` (string (uuid), in path, required): Identifier of the segment within the itinerary named by `itinerary_id`. A segment belonging to another itinerary is a 404, not a 403.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

Where to split the segment, as a fraction of its length between 0 and 1. The one segment becomes two, and the ordering after it shifts.

- `first_name` (string, in body, optional): Display name for the first half, the one that keeps the original segment's identifier. Omit to leave the original's name unchanged. 2 to 30 characters as sent; leading and trailing whitespace is then trimmed, and what remains must still be at least 2 characters. A name is one line: a tab, a line break or a line separator between two of its characters is a `400`, and one at either end is trimmed with the whitespace there.

- `fraction` (number (double), in body, required): Position of the split along the segment, as a fraction of its length in the open interval (0, 1). 0.5 splits it in half.

- `second_name` (string, in body, optional): Display name for the second half, the segment created after the first. Omit to inherit the original's name. 2 to 30 characters as sent; leading and trailing whitespace is then trimmed, and what remains must still be at least 2 characters. A name is one line: a tab, a line break or a line separator between two of its characters is a `400`, and one at either end is trimmed with the whitespace there.

**Response** `201`

The whole itinerary after the split: one segment has become two, and the ordering after them has shifted. `Location` names the second half, the segment the split created, `/v1/itineraries/{itinerary_id}/segments/{segment_id}`, and `extensions.metadata.created.id` is its identifier. `ETag` carries the itinerary's new version.

- `extensions` (object, required): The envelope's second half, everything the answer carries that is not the answer itself. Here that is `metadata.created`, the second half, the segment this split created.
  - `metadata` (ResponseMetadataCreatedPart, required): What a write that created a part of an itinerary created, at `extensions.metadata` of its `201`. The answer's `data` is the whole itinerary, as every write to one answers it, so this is how a client finds the part it just made without searching for it; `Location` names the same part.
    - `created` (object, required): The part created.
      - `id` (string (uuid), required): Identifier of the segment, segment group or waypoint created. On a split, the second of the two segments, the one the split made.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `Location`: The path of what the request created, relative to this host. A part of an itinerary is addressed under its itinerary, so a new segment's is `/v1/itineraries/{itinerary_id}/segments/{segment_id}`.
- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Either no itinerary with that identifier is reachable, because none exists or this credential cannot view it, or that itinerary holds no segment with the identifier given. A segment that belongs to another itinerary answers the same way as one that does not exist, so neither identifier can be probed here. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does.
- `409`: Conflict, from either of two causes. Both carry `extensions.code` `CONFLICT`, so what tells them apart is `extensions.metadata`. Present, carrying a holder: another member of the collaboration session holds the edit lock on the segment. The holder is at `extensions.metadata.holder.id`. A body this operation refuses is answered with its `400` before any lock is looked at, so a peer's lock is reported only for a request that is otherwise well formed. Absent: the chain, or a segment this split was computed from, changed between the read it was planned against and the write: another writer reordered the chain, or changed the segment or a neighbour, by a peer's edit, a segment inserted beside it or a neighbour's drag. Nothing is split; retry against a fresh read. Nothing holds a lock, so there is no holder to name and `extensions` is not required. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# `fraction` is where along the segment to cut, 0 to 1 exclusive of both ends.
curl -s -X POST https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c/split \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "fraction": 0.4,
    "first_name": "Col de Voza approach",
    "second_name": "Descent to Les Contamines"
  }'
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.postItinerarySegmentSplit({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  segment_id: "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
  body: {
    fraction: 0.4,
    first_name: "Col de Voza approach",
    second_name: "Descent to Les Contamines",
  },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.post(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segments/2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c/split",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "fraction": 0.4,
        "first_name": "Col de Voza approach",
        "second_name": "Descent to Les Contamines",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 201:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  },
  "extensions": {
    "metadata": {
      "created": {
        "id": "2c8e5f13-7a94-4b06-8d21-9e3f0a6c7b58"
      }
    }
  }
}
```

## Group a contiguous run of an itinerary's segments

### POST /v1/itineraries/{itinerary_id}/segment-groups

- Operation: `postItinerarySegmentGroup`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: answers within 30000 ms or times out

Creates a segment group over the given segments. The segments themselves are unchanged: grouping only overrides the name, color, and speed shown for that run on the elevation profile and in the segment chooser, and every member stays individually selectable and editable.

Refused with 400 when the segments do not form a contiguous run of the chain, when fewer than two are given, or when any of them does not belong to this itinerary.

Refused with 409, its entries coded `CONFLICT`, when any of them already belongs to another group: one entry per such segment, naming its position in `segment_ids`. That is a state of the chain rather than a fault in the request, refused the same way until the other group lets the segment go, so leave it out of the run or change that group first.

Refused with 409 as well when a concurrent writer reached the same segments first, either by grouping one of them between the validation and the write, or by reordering the chain so the run the request names stops being contiguous. Both are validated against the chain as the caller last read it and re-asserted under the chain lock before anything is written, so the loser of a race is told to reload rather than silently taking the winner's members or committing a broken run. The two read the same on the wire and call for the same response: re-read the itinerary and decide again against what it holds.

Unlike the 409 on patchItinerarySegmentGroup and deleteItinerarySegmentGroup, this one never carries `extensions.metadata.holder` and uses the generic conflict shape: a holder identifies the collaborator whose lock refused the write, and there is no group to hold a lock on yet.

Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does: creating a group rewrites the group_id of every member, so the group alone would leave the client's segments stale. `Location` and `extensions.metadata.created.id` name the group created.

Send the itinerary's `ETag` as `If-Match` to make the create conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is created.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment_group.created`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-created), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment_group.create`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The new group's name and color, and the segments it gathers.

- `color` (string, in body, required): Hex color code used to paint the whole run as one band. Required, because a group with no color is indistinguishable from no group at all. Both the three-digit and the six-digit forms are accepted, in either case, and either is stored as six lowercase digits (`#F60` and `#FF6600` both as `#ff6600`), which is the form every read returns.

- `name` (string, in body, required): Display name of the segment group, 2 to 30 characters as sent. Leading and trailing whitespace is then trimmed, and what remains must still be at least 2 characters. A name is one line: a tab, a line break or a line separator between two of its characters is a `400`, and one at either end is trimmed with the whitespace there.

- `segment_ids` (array of string (uuid), in body, required): Identifiers of the segments to group. They must form a contiguous run of the itinerary's chain (their positions must be consecutive, in any order within the array) and none may already belong to another group.

  At least two are required: a one-segment group is indistinguishable from setting that segment's own name and color. The upper bound is the one every identifier array on this surface carries.

  A repeated identifier is refused rather than collapsed, because a repeat would make the run read as shorter than it is and let a selection that is not contiguous pass the span check.

- `speed` (number (double), in body, optional): Travel speed in km/h applied to the whole run when computing the displayed duration. At least 0.01 and at most 999.99, and stored rounded to two decimal places.

  Optional and not nullable: omit it for no override, in which case each member segment keeps using its own speed. The update operation types the same field nullable, because there `null` removes an override.

**Response** `201`

The whole itinerary, with the new group and the segments gathered into it. `Location` names the group, `/v1/itineraries/{itinerary_id}/segment-groups/{group_id}`, and `extensions.metadata.created.id` is its identifier. `ETag` carries the itinerary's new version.

- `extensions` (object, required): The envelope's second half, everything the answer carries that is not the answer itself. Here that is `metadata.created`, the segment group this request created.
  - `metadata` (ResponseMetadataCreatedPart, required): What a write that created a part of an itinerary created, at `extensions.metadata` of its `201`. The answer's `data` is the whole itinerary, as every write to one answers it, so this is how a client finds the part it just made without searching for it; `Location` names the same part.
    - `created` (object, required): The part created.
      - `id` (string (uuid), required): Identifier of the segment, segment group or waypoint created. On a split, the second of the two segments, the one the split made.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `Location`: The path of what the request created, relative to this host. A part of an itinerary is addressed under its itinerary, so a new segment's is `/v1/itineraries/{itinerary_id}/segments/{segment_id}`.
- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: No itinerary with that identifier is reachable: either none exists, or this credential cannot view it. The two answer alike, so this status cannot be used to learn which itinerary ids exist. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does.
- `409`: One of the segments already belongs to another group: one entry per such segment, each naming its position in `segment_ids`. Nothing is grouped, and the same request is refused the same way until the other group lets the segment go. A concurrent writer reached the same segments first, either by grouping one of them between the validation and the write, or by reordering the chain so the run the request names stops being contiguous. Both read the same on the wire and call for the same response: re-read the itinerary and decide again against what it holds. Unlike the 409 on `patchItinerarySegmentGroup` and `deleteItinerarySegmentGroup`, this one never carries `extensions.metadata.holder`, because there is no group yet for a collaborator to hold a lock on. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# A group needs at least two segments and they must be consecutive in the chain:
# a one-segment group would just be that segment's own name and color.
curl -s -X POST https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segment-groups \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Days 1-2",
    "color": "#2f80ed",
    "segment_ids": [
      "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
      "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a"
    ],
    "speed": 4.5
  }'
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.postItinerarySegmentGroup({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  body: {
    name: "Days 1-2",
    color: "#2f80ed",
    segment_ids: [
      "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
      "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
    ],
    speed: 4.5,
  },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.post(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segment-groups",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "name": "Days 1-2",
        "color": "#2f80ed",
        "segment_ids": [
            "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
            "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
        ],
        "speed": 4.5,
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 201:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  },
  "extensions": {
    "metadata": {
      "created": {
        "id": "2c8e5f13-7a94-4b06-8d21-9e3f0a6c7b58"
      }
    }
  }
}
```

## Update a segment group

### PATCH /v1/itineraries/{itinerary_id}/segment-groups/{group_id}

- Operation: `patchItinerarySegmentGroup`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Updates the group's name, color, speed, or membership. Membership changes obey the same rules as creation: the segments must form a contiguous run of the chain and at least two are required, each a 400 otherwise, and none may already belong to another group, a 409 naming each such segment's position in `segment_ids`. Segments dropped from the run are un-grouped.

A group is presentation only, so no update here ever touches a member segment's geometry, metrics, or position. The lock this operation contends on is the group's own, so renaming a group while a collaborator edits one of its members' geometry is legal and expected.

Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does: a membership change rewrites the group_id of every segment entering or leaving the run.

Send the itinerary's `ETag` as `If-Match` to make the update conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is changed.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment_group.updated`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-updated), [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment_group.update`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

- `group_id` (string (uuid), in path, required): Identifier of the segment group within the itinerary named by `itinerary_id`.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The fields to change. A field you omit keeps its stored value, and a nullable field sent as `null` is cleared. A field the body does not declare, such as `revision`, is a `400` naming it: no request takes a revision.

- `color` (string, in body, optional): Hex color code used to paint the whole run as one band. Both the three-digit and the six-digit forms are accepted, in either case, and either is stored as six lowercase digits (`#F60` and `#FF6600` both as `#ff6600`), which is the form every read returns. Optional and not nullable: omit it to keep the current color. A group always has one, so there is nothing for `null` to clear.

- `name` (string, in body, optional): Display name of the segment group, 2 to 30 characters as sent. Leading and trailing whitespace is then trimmed, and what remains must still be at least 2 characters. Optional and not nullable: omit it to keep the current name. A name is one line: a tab, a line break or a line separator between two of its characters is a `400`, and one at either end is trimmed with the whitespace there.

- `segment_ids` (array of string (uuid), in body, optional): The group's new membership, replacing the current one. Optional and not nullable: omit it to leave the membership untouched. Same rules as on creation: the segments must form a contiguous run of the itinerary's chain, none may already belong to another group, and at least two are required. Segments dropped from the array are un-grouped; to dissolve the group entirely, delete it instead. The upper bound is the one every identifier array on this surface carries, and a repeated identifier is refused rather than collapsed, for the reason creation gives.

- `speed` (number (double) | null, in body, optional): Travel speed in km/h applied to the whole run when computing the displayed duration. At least 0.01 and at most 999.99, and stored rounded to two decimal places. Omit it to keep the current override; `null` removes it, and each member segment falls back to its own speed.

**Response** `200`

The whole itinerary after the update, and its new `ETag`.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Either no itinerary with that identifier is reachable, because none exists or this credential cannot view it, or that itinerary holds no segment group with the identifier given. A segment group that belongs to another itinerary answers the same way as one that does not exist, so neither identifier can be probed here. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does.
- `409`: Conflict, from one of three causes. Each carries `extensions.code` `CONFLICT`; `extensions.metadata` names a holder only where a lock is the cause. One of the segments `segment_ids` names already belongs to another group: one entry per such segment, each naming its position in `segment_ids`. Nothing is changed, and the same request is refused the same way until the other group lets the segment go. Present, carrying a holder: another member of the collaboration session holds the edit lock on the group. The holder is at `extensions.metadata.holder.id`. A body this operation refuses is answered with its `400` before any lock is looked at, so a peer's lock is reported only for a request that is otherwise well formed. Absent: a concurrent writer reached the requested segments first, either by grouping one of them between the validation and the write, or by reordering or shortening the chain so the run the request names is broken: a gap opened in it, or one of its segments was removed. Membership and the run's shape are both re-asserted under the chain lock, so the loser of a race is told to reload rather than silently taking the winner's members or committing a broken run. Only a request that sends `segment_ids` meets this. Nobody is editing, somebody simply committed first, so there is no holder to name and `extensions` is not required. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# `segment_ids`, when sent, is the whole new membership: segments dropped from it are
# un-grouped. A field you omit keeps its stored value.
curl -s -X PATCH https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segment-groups/5d7c3a81-9e24-4b06-8f1d-3a6c9b204e78 \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Days 1-3",
    "color": "#27ae60",
    "segment_ids": [
      "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
      "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
      "15a9d3c7-8e02-4b6f-9d41-6f7a2c8e0b53"
    ],
    "speed": null
  }'
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.patchItinerarySegmentGroup({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  group_id: "5d7c3a81-9e24-4b06-8f1d-3a6c9b204e78",
  body: {
    name: "Days 1-3",
    color: "#27ae60",
    segment_ids: [
      "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
      "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
      "15a9d3c7-8e02-4b6f-9d41-6f7a2c8e0b53",
    ],
    speed: null,
  },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.patch(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segment-groups/5d7c3a81-9e24-4b06-8f1d-3a6c9b204e78",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "name": "Days 1-3",
        "color": "#27ae60",
        "segment_ids": [
            "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
            "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
            "15a9d3c7-8e02-4b6f-9d41-6f7a2c8e0b53",
        ],
        "speed": None,
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  }
}
```

## Delete a segment group

### DELETE /v1/itineraries/{itinerary_id}/segment-groups/{group_id}

- Operation: `deleteItinerarySegmentGroup`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Dissolves the group. Its members are un-grouped and are otherwise untouched: each keeps its own name, color, speed, geometry, metrics, and position, and the elevation profile goes back to showing them as separate bands. No segment is ever deleted by this operation. Clearing a member's `group_id` writes no new revision of it, so its `revision` does not move.

Returns the whole itinerary with its segments, waypoints, and groups, as every write to an itinerary's parts does, so the client sees the cleared group_id on every former member.

Send the itinerary's `ETag` as `If-Match` to make the delete conditional on nobody having changed the itinerary since you read it; a stale tag is refused with `412` and nothing is deleted.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Webhook events** [`itinerary.segment_group.deleted`](https://docs.mountaya.com/en/webhooks/events/itinerary-segment-group.md#itinerary-segment-group-deleted), recorded by the task `itinerary.segment_group.delete`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

- `group_id` (string (uuid), in path, required): Identifier of the segment group within the itinerary named by `itinerary_id`.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200`

The whole itinerary after the group is removed. The segments it gathered survive, ungrouped.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (ItineraryWithDetails, required): An itinerary with its full list of segments, waypoints, and segment groups included, plus its derived publication state.

  See [the ItineraryWithDetails object](https://docs.mountaya.com/en/apis/map-studio/reference/itineraries.md#itinerary-with-details-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `412`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement: the organization does not hold Embedded Studio, the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member. It is agreed rather than bought, so it clears when the organization's agreement changes rather than when the request does. The product is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. The reads that take `publishing` are unaffected. It is also a plain `PAYMENT_REQUIRED` when the organization the itinerary belongs to does not hold Map Studio, which every change to an organization's itineraries, collections and zones needs. Map Studio is granted by the organization's agreement, so this too clears when the agreement changes rather than when the request does.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only, or the itinerary is one this credential can read and not edit, such as another organization's public itinerary while its publication is served. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Either no itinerary with that identifier is reachable, because none exists or this credential cannot view it, or that itinerary holds no segment group with the identifier given. A segment group that belongs to another itinerary answers the same way as one that does not exist, so neither identifier can be probed here. So does an itinerary that has never been published, or has been taken down, or whose organization's agreement does not include Map Publishing, when this credential reads it as published rather than as its draft: a write answers it as a read does. A second delete of the same group answers here too: send a retried delete with the same `Idempotency-Key` and it is answered with the first one's

1. 

- `409`: Conflict, from either of two causes. Both carry `extensions.code` `CONFLICT`, so what tells them apart is `extensions.metadata`. Present, carrying a holder: another member of the collaboration session holds the edit lock on the group. The holder is at `extensions.metadata.holder.id`. Absent: a concurrent writer changed the chain between the validation and the write. Nobody is editing, somebody simply committed first, so there is no holder to name: re-read the itinerary and decide again. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Deletes the grouping only. The segments inside it stay, un-grouped and in place.
curl -s -X DELETE https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segment-groups/5d7c3a81-9e24-4b06-8f1d-3a6c9b204e78 \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

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

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.itineraries.deleteItinerarySegmentGroup({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  group_id: "5d7c3a81-9e24-4b06-8f1d-3a6c9b204e78",
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.delete(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/segment-groups/5d7c3a81-9e24-4b06-8f1d-3a6c9b204e78",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
    "organization_id": "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
    "activity_id": "a1c4e7b2-3d59-4f08-8b6a-2e5c9d0f7134",
    "name": "Tour du Mont-Blanc",
    "description": "Ten stages from Les Houches, anticlockwise.",
    "is_private": false,
    "is_verified": true,
    "distance": 169800,
    "ascent": 9800,
    "count": {
      "groups": 3,
      "segments": 10,
      "waypoints": 24
    },
    "revision": 42,
    "etag": "\"d118\"",
    "created_by": {
      "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
    },
    "created_at": "2026-05-12T09:14:00Z",
    "updated_at": "2026-06-28T16:02:00Z",
    "status": "published",
    "published_at": "2026-06-28T16:05:00Z",
    "has_unpublished_changes": false,
    "groups": [
      {
        "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "name": "Days 1-2",
        "color": "#2f80ed",
        "speed": 4.5,
        "revision": 2,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "segments": [
      {
        "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23",
        "name": "Day 1: Col de Voza",
        "description": "From Les Houches over the Col de Voza, down the Bon Nant valley.",
        "mode": "directions",
        "position": 0,
        "color": "#2f80ed",
        "speed": 4.5,
        "start_at": "2026-07-04T07:30:00Z",
        "distance": 17400,
        "duration": 14760,
        "ascent": 1080,
        "descent": 720,
        "altitude_min": 942,
        "altitude_max": 1653,
        "gradient_min": -18.4,
        "gradient_max": 21.7,
        "geojson": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "LineString",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.7621,
                  45.8842
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            },
            {
              "type": "MultiPoint",
              "coordinates": [
                [
                  6.7986,
                  45.8918
                ],
                [
                  6.728,
                  45.8215
                ]
              ]
            }
          ]
        },
        "slope_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 12.4
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": -8.1
          }
        ],
        "speed_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": 2.9
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": 5.6
          }
        ],
        "surface_info": [
          {
            "from_index": 0,
            "to_index": 1,
            "value": "compacted-gravel"
          },
          {
            "from_index": 1,
            "to_index": 2,
            "value": "dirt"
          }
        ],
        "way_type_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "path"
          }
        ],
        "trail_difficulty_info": [
          {
            "from_index": 0,
            "to_index": 2,
            "value": "mountain-hiking"
          }
        ],
        "steps": [
          {
            "from_index": 0,
            "to_index": 1,
            "type": "depart",
            "name": "Route des Chavants",
            "distance": 8400,
            "duration": 7200,
            "exit_number": null
          },
          {
            "from_index": 1,
            "to_index": 2,
            "type": "goal",
            "name": "-",
            "distance": 9000,
            "duration": 7560,
            "exit_number": null
          }
        ],
        "road_access_info": [
          {
            "from_index": 1,
            "to_index": 2,
            "values": [
              "private"
            ]
          }
        ],
        "revision": 7,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ],
    "waypoints": [
      {
        "id": "e8b1d740-2a96-4c53-b7f8-15d0a3c69e42",
        "itinerary_id": "9c2a7f60-1d4b-4e83-a5c7-6f0b8e91d245",
        "mode": "poi",
        "position": 0,
        "name": "Refuge du Fioux",
        "description": "Half-board, book ahead in July.",
        "icon": "hut",
        "color": "#f2994a",
        "geojson": {
          "type": "Point",
          "coordinates": [
            6.7612,
            45.8479
          ]
        },
        "amenities": [
          "water",
          "hot-meal",
          "accommodation",
          "toilets",
          "timing-checkpoint"
        ],
        "timing": {
          "cutoff_at": "2026-08-28T21:30:00Z",
          "stop_duration": 900
        },
        "contact": {
          "website": "https://www.example.com/refuge",
          "phone": "+33 4 50 12 34 56",
          "email": "contact@example.com",
          "address": "74170 Les Contamines-Montjoie, France",
          "opening_hours": "Mid-June to mid-September, 07:00-21:00 daily.",
          "booking_url": "https://www.example.com/refuge/reserver"
        },
        "media": {
          "photos": [
            {
              "url": "https://cdn.example.com/refuge-du-fioux/terrace.jpg",
              "caption": "The terrace at sunrise."
            }
          ],
          "links": [
            {
              "label": "Access from Les Contamines",
              "url": "https://www.example.com/access/les-contamines"
            }
          ]
        },
        "properties": [
          {
            "key": "bib-check",
            "label": "Bib check",
            "value": "Mandatory, both sides",
            "format": "text"
          }
        ],
        "revision": 3,
        "created_by": {
          "id": "7a3e5d18-4c60-49b2-8f75-e2d1c9a4b607"
        },
        "created_at": "2026-05-12T09:14:00Z"
      }
    ]
  }
}
```

**Error answers the operations of this page share**

- `PreconditionFailed` (`412`): `If-Match` named a version the resource has moved on from: somebody changed it after the caller read it. Nothing was changed. The one entry is coded `PRECONDITION_FAILED`, and `ETag` carries the current version, so read the resource again, decide whether the change still applies, and send it with the new tag. Retrying with the same tag is refused the same way. A resource the caller cannot see is answered `404` before the condition is asked, and a write refused for any other reason is refused for that reason first.
- `TooManyRequests` (`429`): A limit on this operation's requests is spent: the [rate limits](https://docs.mountaya.com/en/apis/conventions/rate-limits.md) page lists every one, the unknown publishable keys one address may present among them, and the operation's description names any of its own. The request was counted and nothing was done. `Retry-After` says how long until the limit lifts; wait that long, with a little jitter of your own, and send the request again. Where the operation takes an `Idempotency-Key`, a write sent again with the same key runs once.
