Get started

Edit an itinerary's route

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

Before you start

Writes act as a member, so mint a session token that names one, as in the quickstart:

export MOUNTAYA_MEMBER_TOKEN=$(curl -s -X POST https://api.mountaya.com/v1/sessions \
  -H "X-API-Key: $MOUNTAYA_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"publishable_key\": \"$MOUNTAYA_PUBLISHABLE_KEY\", \"user_id\": \"7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1\", \"surface\": \"studio-embedded\"}" \
  | jq -r .data.token)

The examples below edit $ITINERARY_ID, an itinerary of yours with one segment.

Read the chain

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

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

SEGMENT_ID=$(echo "$ITINERARY" | jq -r '.data.segments[0].id')
echo "$ITINERARY" | jq '[.data.segments[] | {id, position, name, mode}]'
Response
[
  {
    "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    "position": 0,
    "name": "Chamonix to Argentière",
    "mode": "directions"
  }
]

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

Insert a segment

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

INSERTED=$(curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d @- <<JSON
{
  "name": "Les Houches to Chamonix",
  "mode": "directions",
  "before_segment_id": "$SEGMENT_ID",
  "geojson": {"type": "MultiPoint", "coordinates": [[6.7991, 45.8915], [6.8712, 45.9231]]}
}
JSON
)

INSERTED_SEGMENT=$(echo "$INSERTED" | jq -r .extensions.metadata.created.id)
echo "$INSERTED" | jq '[.data.segments[] | {id, position, name}]'
Response
[
  {
    "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
    "position": 0,
    "name": "Les Houches to Chamonix"
  },
  {
    "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    "position": 1,
    "name": "Chamonix to Argentière"
  }
]

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

Split a segment

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

curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments/$SEGMENT_ID/split \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"fraction": 0.5, "first_name": "Chamonix to Les Tines", "second_name": "Les Tines to Argentière"}' \
  | jq '[.data.segments[] | {id, position, name}]'
Response
[
  {
    "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a",
    "position": 0,
    "name": "Les Houches to Chamonix"
  },
  {
    "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c",
    "position": 1,
    "name": "Chamonix to Les Tines"
  },
  {
    "id": "15a9d3c7-8e02-4b6f-9d41-6f7a2c8e0b53",
    "position": 2,
    "name": "Les Tines to Argentière"
  }
]

Merge segments

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

curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments/$SEGMENT_ID/merge \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  | jq '[.data.segments[] | {id, position}]'
Response
[
  { "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a", "position": 0 },
  { "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c", "position": 1 }
]

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

Switch between routed and drawn

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

curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segments/$SEGMENT_ID/convert \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"mode": "linestring"}' \
  | jq '[.data.segments[] | {id, mode}]'
Response
[
  { "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a", "mode": "directions" },
  { "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c", "mode": "linestring" }
]

Group segments

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

curl -s -X POST https://api.mountaya.com/v1/itineraries/$ITINERARY_ID/segment-groups \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_MEMBER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"name\": \"Day 1\", \"color\": \"#2f80ed\", \"segment_ids\": [\"$INSERTED_SEGMENT\", \"$SEGMENT_ID\"]}" \
  | jq '{groups: [.data.groups[] | {id, name}], segments: [.data.segments[] | {id, group_id}]}'
Response
{
  "groups": [
    { "id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23", "name": "Day 1" }
  ],
  "segments": [
    { "id": "7e1c5a92-4b60-4d38-a7f2-0c9e6b3d854a", "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23" },
    { "id": "2b8d4f19-6a05-4e73-8c1f-9d3b7e05a24c", "group_id": "5c6e2a71-3f84-4b9d-90e5-8a1c7b4f6d23" }
  ]
}

Mark a place with a waypoint

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

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

PATCH a waypoint to add services or a cut-off, as the race course tutorial does.

Remove a segment

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

Next steps

Last updated