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

# Complete Operation

> Mark an operation as done: sets `completed_at` to now and clears any cancellation. Some operations change the rest of the route, returned in `side_effects`: completing a `recharge_pickup` adds a `start_charge` right after it, and completing a `start_charge` moves the next open `end_charge` to the same place. Drivers assigned to the route can complete its operations whatever their company.

**Failure Modes:**
- **401**: Token is missing or invalid
- **403**: Insufficient permissions, or you cannot manage the route's company and are not one of its drivers
- **404**: No route with this ID, or no such operation on it

**Required Auth Scopes:**
- `routing-operations:manage`



## OpenAPI

````yaml /api-reference/openapi.json post /operations/routes/{route_id}/operations/{op_id}/complete
openapi: 3.1.0
info:
  title: SWITCH API
  version: '1.0'
  description: >-
    The SWITCH API gives mobility and logistics teams programmatic access to
    SWITCH forecasts, fleet operations, routing and analytics. Every request is
    authenticated with an API key sent as a bearer token.
servers:
  - url: https://api.getswitch.io
    description: Production
security: []
tags:
  - name: Forecast
    description: Demand forecasts per zone and time window.
  - name: Operations
    description: Fleet imbalance, rebalancing suggestions and generated tasks.
  - name: Routing
    description: Route optimisation for single and multiple fleets.
  - name: Routing Sessions
    description: Saved routing sessions, their routes and drivers.
  - name: Routing Operations
    description: Complete, undo and re-route the stops of a route.
  - name: Fleet Management
    description: Your depots, stations, drivers and cargo vehicles.
  - name: Integrations
    description: Vehicles, statuses and commands on your fleet platform.
  - name: Station Based Analytics
    description: Analytics for station-based (docked) services.
  - name: Zone Based Analytics
    description: Analytics for free-floating services, by zone.
  - name: Free Float Analytics
    description: Trip history for free-floating services.
  - name: Transit Analytics
    description: Punctuality and service delivery for public transit.
  - name: Live
    description: Real-time fleet, delivery and transit status.
  - name: Grids
    description: Spatial grids used by forecasts and analytics.
  - name: API Keys
    description: Create and manage the API keys you call this API with.
paths:
  /operations/routes/{route_id}/operations/{op_id}/complete:
    post:
      tags:
        - Routing Operations
      summary: Complete Operation
      description: >-
        Mark an operation as done: sets `completed_at` to now and clears any
        cancellation. Some operations change the rest of the route, returned in
        `side_effects`: completing a `recharge_pickup` adds a `start_charge`
        right after it, and completing a `start_charge` moves the next open
        `end_charge` to the same place. Drivers assigned to the route can
        complete its operations whatever their company.


        **Failure Modes:**

        - **401**: Token is missing or invalid

        - **403**: Insufficient permissions, or you cannot manage the route's
        company and are not one of its drivers

        - **404**: No route with this ID, or no such operation on it


        **Required Auth Scopes:**

        - `routing-operations:manage`
      operationId: complete_operation
      parameters:
        - name: route_id
          in: path
          required: true
          schema:
            type: integer
            description: Route ID, from the session detail or the route list.
            title: Route Id
          description: Route ID, from the session detail or the route list.
        - name: op_id
          in: path
          required: true
          schema:
            type: integer
            description: Operation ID, from the route's `operations`.
            title: Op Id
          description: Operation ID, from the route's `operations`.
      responses:
        '200':
          description: >-
            Operation completed. Returns the updated operation and any
            side-effect operations.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompleteOperationResponse'
        '401':
          description: Unauthorized. Token is missing or invalid.
        '403':
          description: Forbidden. Insufficient permissions.
        '404':
          description: Not Found. Route or operation not found.
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '500':
          description: Internal Server Error.
      security:
        - HTTPBearer: []
        - HTTPBearer: []
components:
  schemas:
    CompleteOperationResponse:
      properties:
        operation:
          $ref: '#/components/schemas/OperationPublic'
          description: The completed operation.
        side_effects:
          items:
            $ref: '#/components/schemas/OperationPublic'
          type: array
          title: Side Effects
          description: >-
            Operations added or changed as a consequence, e.g. the
            `start_charge` added after a `recharge_pickup`, or the next
            `end_charge` moved to the charging location of a `start_charge`.
      type: object
      required:
        - operation
      title: CompleteOperationResponse
      description: >-
        Response for completing an operation, includes any side-effect
        operations.
      examples:
        - operation:
            additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
            address: Via Mazzini 9, 20123 Milano MI
            completed_at: '2026-11-30T08:25:10Z'
            estimated_arrive: '2026-11-30T08:23:00Z'
            id: 9032
            latitude: 45.4671
            longitude: 9.1883
            provider: acme-mobility
            routing_parameters:
              capacity_delta:
                vehicles: 1
              profit: 3
            step: 2
            task_type: recharge_pickup
          side_effects:
            - address: Via Mazzini 9, 20123 Milano MI
              estimated_arrive: '2026-11-30T08:25:10Z'
              id: 9033
              latitude: 45.4671
              longitude: 9.1883
              provider: acme-mobility
              routing_parameters: {}
              step: 3
              task_type: start_charge
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    OperationPublic:
      properties:
        id:
          type: integer
          title: Id
          description: Operation ID.
        step:
          type: integer
          title: Step
          description: Position of the operation in the route.
        task_type:
          type: string
          title: Task Type
          description: What the operator does at the stop, e.g. `pickup`.
        latitude:
          type: number
          title: Latitude
          description: Latitude of the stop (WGS84).
        longitude:
          type: number
          title: Longitude
          description: Longitude of the stop (WGS84).
        provider:
          type: string
          title: Provider
          description: Fleet the vehicle belongs to.
        address:
          type:
            - string
            - 'null'
          title: Address
          description: Street address, if known.
        vehicle_properties:
          $ref: '#/components/schemas/VehicleWithoutZone'
          description: Snapshot of the vehicle at planning time.
        estimated_arrive:
          type: string
          format: date-time
          title: Estimated Arrive
          description: Estimated arrival time.
        routing_parameters:
          additionalProperties: true
          type: object
          title: Routing Parameters
          description: Free-form data of the stop, as dispatched.
        completed_at:
          type:
            - string
            - 'null'
          format: date-time
          title: Completed At
          description: When the operation was completed; absent while open.
        cancelled:
          type:
            - string
            - 'null'
          title: Cancelled
          description: Cancellation reason; absent unless cancelled.
        additional_notes:
          type:
            - string
            - 'null'
          title: Additional Notes
          description: Free-text notes.
      type: object
      required:
        - id
        - step
        - task_type
        - latitude
        - longitude
        - provider
        - estimated_arrive
        - routing_parameters
      title: OperationPublic
      description: Operation as returned in session detail responses.
      examples:
        - additional_notes: Battery level (12.0%) below threshold (20.0%)
          address: Via Torino 2, 20123 Milano MI
          completed_at: '2026-11-30T08:17:42Z'
          estimated_arrive: '2026-11-30T08:14:00Z'
          id: 9031
          latitude: 45.4642
          longitude: 9.1856
          provider: acme-mobility
          routing_parameters:
            capacity_delta:
              charged_battery: -1
              empty_battery: 1
            profit: 2.4
          step: 1
          task_type: battery_swap
          vehicle_properties:
            battery_level: 12
            id: acme-sc-0193
            last_moved: '2026-11-30T06:41:03Z'
            last_seen: '2026-11-30T07:50:12Z'
            lat: 45.4642
            licence_plate: SC0193
            lon: 9.1856
            status: available
            vehicle_model: S-200
            vehicle_type: scooter
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    VehicleWithoutZone:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the vehicle
        licence_plate:
          type:
            - string
            - 'null'
          title: Licence Plate
          description: Licence plate number of the vehicle
        lat:
          type:
            - number
            - 'null'
          title: Lat
          description: Latitude of the vehicle's current location
        lon:
          type:
            - number
            - 'null'
          title: Lon
          description: Longitude of the vehicle's current location
        vehicle_type:
          type:
            - string
            - 'null'
          title: Vehicle Type
          description: Type of the vehicle, e.g., 'scooter', 'bike', 'car'
        vehicle_model:
          type:
            - string
            - 'null'
          title: Vehicle Model
          description: Model of the vehicle, e.g., 'Model X', 'Model Y'
        battery_level:
          type:
            - integer
            - 'null'
          title: Battery Level
          description: Battery level of the vehicle, e.g., 100 for 100%
        battery_level_master:
          type:
            - integer
            - 'null'
          title: Battery Level Master
          description: >-
            Master battery level percentage (custom MDS setup only). None when
            not reported by the provider.
        last_seen:
          type:
            - string
            - 'null'
          format: date-time
          title: Last Seen
          description: Timestamp of the last time the vehicle was seen in the system
        last_moved:
          type:
            - string
            - 'null'
          format: date-time
          title: Last Moved
          description: Timestamp of the last time the vehicle moved
        status:
          type:
            - string
            - 'null'
          title: Status
          description: Current status of the vehicle, e.g., 'available', 'in-use'
      type: object
      required:
        - id
        - battery_level
      title: VehicleWithoutZone
      description: >-
        Represents a vehicle without zone assignment.


        Base schema containing all vehicle attributes except zone_id.

        Used when a grid service is not available and spatial zone mapping is
        skipped.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer
      description: >-
        An API key, sent as `Authorization: Bearer <key>`. Create one in the
        SWITCH Copilot under **Settings → API keys** (needs the API keys
        permission in your company), or with `POST /auth/api-keys`. The key is
        shown once, at creation.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.