> ## 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.

# Apply Rerouted Operations

> Replace the open operations of a route with `new_operations`, usually from `reroute/generate`. Completed and cancelled operations stay; the new ones follow them in the given order. All or nothing.

**Failure Modes:**
- **401**: Token is missing or invalid
- **400**: Rerouting is not enabled on the route, or it has no open operations
- **403**: Insufficient permissions, or you cannot manage the route's company
- **404**: No route with this ID, or its session was deleted
- **422**: Missing or empty `new_operations`

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



## OpenAPI

````yaml /api-reference/openapi.json post /operations/routes/{route_id}/reroute/apply
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}/reroute/apply:
    post:
      tags:
        - Routing Operations
      summary: Apply Rerouted Operations
      description: >-
        Replace the open operations of a route with `new_operations`, usually
        from `reroute/generate`. Completed and cancelled operations stay; the
        new ones follow them in the given order. All or nothing.


        **Failure Modes:**

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

        - **400**: Rerouting is not enabled on the route, or it has no open
        operations

        - **403**: Insufficient permissions, or you cannot manage the route's
        company

        - **404**: No route with this ID, or its session was deleted

        - **422**: Missing or empty `new_operations`


        **Required Auth Scopes:**

        - `routing-operations:manage`
      operationId: apply_reroute
      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.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RerouteApplyRequest'
      responses:
        '200':
          description: Reroute applied. Returns removed/inserted counts.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RerouteApplyResponse'
        '400':
          description: Bad Request. Rerouting disabled or no pending ops.
        '401':
          description: Unauthorized. Token is missing or invalid.
        '403':
          description: Forbidden. Insufficient permissions.
        '404':
          description: Not Found. Route or operation not found.
        '422':
          description: Unprocessable Entity. Invalid payload.
        '500':
          description: Internal Server Error.
      security:
        - HTTPBearer: []
        - HTTPBearer: []
components:
  schemas:
    RerouteApplyRequest:
      properties:
        new_operations:
          items:
            $ref: '#/components/schemas/RerouteSuggestion'
          type: array
          minItems: 1
          title: New Operations
          description: Operations to insert (from a previous generate/optimize call).
      type: object
      required:
        - new_operations
      title: RerouteApplyRequest
      description: |-
        Request body for applying a reroute preview.

        Contains the new operations to insert. This is the output of
        generate/optimize, sent back to apply.
      examples:
        - new_operations:
            - additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
              address: Via Mazzini 9, 20123 Milano MI
              estimated_arrive: '2026-11-30T08:21:00Z'
              latitude: 45.4671
              longitude: 9.1883
              provider: acme-mobility
              routing_parameters:
                capacity_delta:
                  vehicles: 1
                profit: 2.1
              step: 2
              task_type: pickup
    RerouteApplyResponse:
      properties:
        route_id:
          type: integer
          title: Route Id
          description: Route ID.
        removed_operations:
          type: integer
          title: Removed Operations
          description: Number of pending operations removed.
        inserted_operations:
          type: integer
          title: Inserted Operations
          description: Number of new operations inserted.
      type: object
      required:
        - route_id
        - removed_operations
        - inserted_operations
      title: RerouteApplyResponse
      description: Confirmation of a reroute apply action.
      examples:
        - inserted_operations: 1
          removed_operations: 1
          route_id: 412
    RerouteSuggestion:
      properties:
        step:
          type: integer
          title: Step
          description: >-
            Position in the new plan, from 1; applied after the route's
            completed and cancelled operations.
        task_type:
          type: string
          title: Task Type
          description: Operation type, 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:
          additionalProperties: true
          type:
            - object
            - 'null'
          title: Vehicle Properties
          description: Snapshot of the vehicle, carried over from the route.
        estimated_arrive:
          type: string
          format: date-time
          title: Estimated Arrive
          description: Estimated arrival time in the new plan.
        routing_parameters:
          additionalProperties: true
          type: object
          title: Routing Parameters
          description: Free-form data of the stop (`capacity_delta`, `profit`).
        additional_notes:
          type:
            - string
            - 'null'
          title: Additional Notes
          description: Free-text notes.
      type: object
      required:
        - step
        - task_type
        - latitude
        - longitude
        - provider
        - estimated_arrive
      title: RerouteSuggestion
      description: A single operation in the proposed rerouted plan.
      examples:
        - additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
          address: Via Mazzini 9, 20123 Milano MI
          estimated_arrive: '2026-11-30T08:21:00Z'
          latitude: 45.4671
          longitude: 9.1883
          provider: acme-mobility
          routing_parameters:
            capacity_delta:
              vehicles: 1
            profit: 2.1
          step: 2
          task_type: pickup
  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.