> ## Documentation Index
> Fetch the complete documentation index at: https://docs.voyantcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsert Departure Segments

> Replace the primary transport segments for a departure.

## Method

`PUT` `/v1/products/:id/transport/departures/:departureId/segments`

## Path Parameters

<ParamField path="id" type="uuid">Product ID that owns the departure.</ParamField>
<ParamField path="departureId" type="uuid">Departure ID whose segments should be replaced.</ParamField>

## Body Parameters

<ParamField name="segments" type="array" required>Array of segment definitions. Send an empty array to clear all segments.</ParamField>

<Expandable title="Segment object">
  <ParamField name="segments[].mode_id" type="uuid" required>Transport mode ID (must match a configured transportation mode).</ParamField>
  <ParamField name="segments[].operator_org_id" type="uuid">Provider organization ID (required for non-air modes).</ParamField>
  <ParamField name="segments[].resource_id" type="uuid">Optional transport resource ID (vehicle, aircraft, etc.).</ParamField>
  <ParamField name="segments[].from_place_id" type="string">Origin Google Place ID.</ParamField>
  <ParamField name="segments[].to_place_id" type="string">Destination Google Place ID.</ParamField>
  <ParamField name="segments[].depart_offset_minutes" type="integer">Offset (minutes) from departure start.</ParamField>
  <ParamField name="segments[].duration_minutes" type="integer">Duration in minutes.</ParamField>
  <ParamField name="segments[].attributes" type="object">Additional metadata (defaults to `{}`).</ParamField>
  <ParamField name="segments[].notes" type="string">Internal notes.</ParamField>
  <ParamField name="segments[].is_charter" type="boolean">Whether the segment is chartered.</ParamField>
  <ParamField name="segments[].airline_code" type="string">IATA airline code.</ParamField>
  <ParamField name="segments[].flight_number" type="string">Flight number.</ParamField>
  <ParamField name="segments[].cabin_class" type="string">Cabin class label.</ParamField>
  <ParamField name="segments[].fare_class_code" type="string">Fare class.</ParamField>
  <ParamField name="segments[].seats_total" type="integer">Capacity for the segment.</ParamField>
  <ParamField name="segments[].seats_available" type="integer">Available seats.</ParamField>
  <ParamField name="segments[].luggage" type="object">JSON luggage allowances (defaults to `{}`).</ParamField>
</Expandable>

## Headers

<ParamField header="Authorization" type="string">Bearer token (requires `products:write`).</ParamField>
<ParamField header="content-type" type="string">`application/json`</ParamField>

## Request Example

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT "https://api.voyantcloud.com/v1/products/prod_123/transport/departures/dep_456/segments" \
    -H "Authorization: Bearer $VOYANT_API_KEY" \
    -H "content-type: application/json" \
    -d '{
      "segments": [
        {
          "mode_id": "mode_flight",
          "operator_org_id": "org_airline",
          "from_place_id": "ChIJ8UNwppk4j4ARzWPaN9xq_9o",
          "to_place_id": "ChIJGaK-SZcYtUYR0Y1DSXB6QrM",
          "depart_offset_minutes": 0,
          "duration_minutes": 160,
          "airline_code": "RO",
          "flight_number": "381",
          "cabin_class": "economy",
          "seats_total": 40,
          "seats_available": 18,
          "luggage": { "checked_bag": 1 }
        }
      ]
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch("https://api.voyantcloud.com/v1/products/prod_123/transport/departures/dep_456/segments", {
    method: "PUT",
    headers: {
      Authorization: `Bearer ${process.env.VOYANT_API_KEY}`,
      "content-type": "application/json",
    },
    body: JSON.stringify({ segments: [] }),
  })
  ```

  ```python Python theme={null}
  import os, requests

  payload = {
    "segments": [
      {
        "mode_id": "mode_coach",
        "operator_org_id": "org_transport",
        "from_place_id": "ChIJ8UNwppk4j4ARzWPaN9xq_9o",
        "to_place_id": "ChIJGaK-SZcYtUYR0Y1DSXB6QrM",
        "duration_minutes": 45
      }
    ]
  }

  resp = requests.put(
    "https://api.voyantcloud.com/v1/products/prod_123/transport/departures/dep_456/segments",
    headers={
      "Authorization": f"Bearer {os.environ['VOYANT_API_KEY']}",
      "content-type": "application/json",
    },
    json=payload,
  )
  segments = resp.json()["segments"]
  ```
</RequestExample>

## Response

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "segments": [
      {
        "id": "seg_001",
        "departure_id": "dep_456",
        "seq": 1,
        "mode_id": "mode_flight",
        "operator_org_id": "org_airline",
        "resource_id": "res_aircraft",
        "from_place_id": "ChIJ8UNwppk4j4ARzWPaN9xq_9o",
        "to_place_id": "ChIJGaK-SZcYtUYR0Y1DSXB6QrM",
        "depart_offset_minutes": 0,
        "duration_minutes": 160,
        "attributes": {},
        "notes": "Direct flight",
        "is_charter": false,
        "airline_code": "RO",
        "flight_number": "381",
        "cabin_class": "economy",
        "fare_class_code": "Y",
        "seats_total": 40,
        "seats_available": 18,
        "luggage": { "checked_bag": 1 }
      }
    ]
  }
  ```
</ResponseExample>

<Warning>
  This endpoint replaces all existing segments for the departure. Send the complete list you want to persist each time you call it.
</Warning>
