---
title: Update an existing plan
description: Update an existing plan. If the plan `writable` property is false,
  prefer using the [Live Plans API](/api/live-plans).
url: /api/plans/updatePlan
---

# Update an existing plan

`PATCH /plans/{planId}`

````yaml
openapi: 3.1.0
info:
  title: Spoke API
  version: v1
servers:
  - url: https://api.spoke.com/public/v1
security:
  - BasicAuth: []
paths:
  /plans/{planId}:
    patch:
      operationId: updatePlan
      summary: Update an existing plan
      tags:
        - Plans
      description: Update an existing plan. If the plan `writable` property is false, prefer using the [Live Plans API](/api/live-plans).
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: string
                  minLength: 1
                  maxLength: 255
                  description: The title of the plan.
                starts:
                  description: The date the plan starts. Does not accept dates that are too far in the future or past.
                  type: object
                  properties:
                    day:
                      type: integer
                      minimum: 1
                      maximum: 31
                      description: The day of the date.
                    month:
                      type: integer
                      minimum: 1
                      maximum: 12
                      description: The month of the date.
                    year:
                      type: integer
                      minimum: 2000
                      maximum: 2100
                      description: The year of the date.
                  required:
                    - day
                    - month
                    - year
                  additionalProperties: false
                drivers:
                  maxItems: 50
                  type: array
                  items:
                    type: string
                    pattern: ^drivers\/[a-zA-Z0-9---_]{1,50}$
                    description: The driver id, in the format `drivers/<id>`
                  description: The drivers IDs of the plan, in the format `drivers/<id>`, duplicates will be ignored
                depot:
                  description: The depot id, in the format `depots/<id>`. If not provided, the team's Main Depot will be used.
                  anyOf:
                    - type: string
                      pattern: ^depots\/[a-zA-Z0-9---_]{1,50}$
                    - type: "null"
                routeOverrides:
                  description: Overrides for the plan route behavior.
                  anyOf:
                    - type: object
                      properties:
                        startAddress:
                          description: Address of a start location for every route in this plan. If the latitude and longitude fields are set they will override any of the others. The addressName field is not used for geocoding and is only for display purposes.
                          anyOf:
                            - type: object
                              properties:
                                addressName:
                                  description: The name of the address. This will not be used for geocoding, and is only for the final address display purposes.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 255
                                    - type: "null"
                                addressLineOne:
                                  description: The first line of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 255
                                    - type: "null"
                                addressLineTwo:
                                  description: The second line of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 255
                                    - type: "null"
                                city:
                                  description: The city of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                state:
                                  description: The state of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                zip:
                                  description: The zip code of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                country:
                                  description: The country of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                latitude:
                                  description: The latitude of the address in decimal degrees.
                                  anyOf:
                                    - type: number
                                      minimum: -90
                                      maximum: 90
                                    - type: "null"
                                longitude:
                                  description: The longitude of the address in decimal degrees.
                                  anyOf:
                                    - type: number
                                      minimum: -180
                                      maximum: 180
                                    - type: "null"
                              additionalProperties: false
                              description: At least one of the fields is required. If the latitude and longitude fields are set they will override any of the others.
                            - type: "null"
                        endAddress:
                          description: Address of an end location for every route in this plan. If the latitude and longitude fields are set they will override any of the others. The addressName field is not used for geocoding and is only for display purposes.
                          anyOf:
                            - type: object
                              properties:
                                addressName:
                                  description: The name of the address. This will not be used for geocoding, and is only for the final address display purposes.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 255
                                    - type: "null"
                                addressLineOne:
                                  description: The first line of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 255
                                    - type: "null"
                                addressLineTwo:
                                  description: The second line of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 255
                                    - type: "null"
                                city:
                                  description: The city of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                state:
                                  description: The state of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                zip:
                                  description: The zip code of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                country:
                                  description: The country of the address.
                                  anyOf:
                                    - type: string
                                      minLength: 1
                                      maxLength: 100
                                    - type: "null"
                                latitude:
                                  description: The latitude of the address in decimal degrees.
                                  anyOf:
                                    - type: number
                                      minimum: -90
                                      maximum: 90
                                    - type: "null"
                                longitude:
                                  description: The longitude of the address in decimal degrees.
                                  anyOf:
                                    - type: number
                                      minimum: -180
                                      maximum: 180
                                    - type: "null"
                              additionalProperties: false
                              description: At least one of the fields is required. If the latitude and longitude fields are set they will override any of the others.
                            - type: "null"
                        startTime:
                          description: The start time for the driver's work day.
                          anyOf:
                            - type: object
                              properties:
                                hour:
                                  type: integer
                                  minimum: 0
                                  maximum: 23
                                  description: Hour of the day
                                minute:
                                  type: integer
                                  minimum: 0
                                  maximum: 59
                                  description: Minute of the hour
                              required:
                                - hour
                                - minute
                              additionalProperties: false
                              description: Time of day in hours and minutes. Use a 24 hour clock.
                            - type: "null"
                        endTime:
                          description: The end time for the driver's work day.
                          anyOf:
                            - type: object
                              properties:
                                hour:
                                  type: integer
                                  minimum: 0
                                  maximum: 23
                                  description: Hour of the day
                                minute:
                                  type: integer
                                  minimum: 0
                                  maximum: 59
                                  description: Minute of the hour
                              required:
                                - hour
                                - minute
                              additionalProperties: false
                              description: Time of day in hours and minutes. Use a 24 hour clock.
                            - type: "null"
                        maxStops:
                          description: The maximum number of stops that can be allocated per route. Note that this setting will be ignored when vehicle capacity or pickups are being used.
                          anyOf:
                            - type: integer
                              minimum: 0
                              maximum: 9007199254740991
                            - type: "null"
                        drivingSpeed:
                          anyOf:
                            - type: string
                              enum:
                                - slower
                                - average
                                - faster
                              description: How fast drivers drive compared to the Team's average
                            - type: "null"
                        deliverySpeed:
                          description: How fast drivers deliver compared to the Team's average
                          anyOf:
                            - type: string
                              enum:
                                - slower
                                - average
                                - faster
                            - type: "null"
                        vehicleType:
                          description: The type of vehicle used for routes in this plan
                          anyOf:
                            - type: string
                              enum:
                                - bike
                                - scooter
                                - car
                                - small_truck
                                - truck
                                - electric_cargo_bike
                            - type: "null"
                        optimizationSettings:
                          description: Optimization settings for the plan.
                          anyOf:
                            - type: object
                              properties:
                                objective:
                                  description: The primary optimization objective.
                                  anyOf:
                                    - type: string
                                      enum:
                                        - distribute_services
                                    - type: "null"
                                subObjective:
                                  description: The secondary optimization objective.
                                  anyOf:
                                    - type: string
                                      enum:
                                        - equalize_workload
                                        - equalize_time
                                        - maximize_efficiency
                                    - type: "null"
                              additionalProperties: false
                              description: Configures the optimization settings for routes.
                            - type: "null"
                      additionalProperties: false
                    - type: "null"
              additionalProperties: false
              description: |-
                The request body for updating a plan. All the values present in the request will update the plan value, if you wish to update only certain fields, only set them and do not set the others. Any fields not set will not be updated.

                **Important:** Notice that the `drivers` Array will be completely replaced. If a single driver is provided in the request, the plan will have all other previous drivers discarded.
        description: |-
          The request body for updating a plan. All the values present in the request will update the plan value, if you wish to update only certain fields, only set them and do not set the others. Any fields not set will not be updated.

          **Important:** Notice that the `drivers` Array will be completely replaced. If a single driver is provided in the request, the plan will have all other previous drivers discarded.
      parameters:
        - schema:
            type: string
            pattern: ^[a-zA-Z0-9---_]{1,50}$
          in: path
          name: planId
          required: true
          description: The plan id
      responses:
        "200":
          description: The updated plan
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/planSchema"
                description: The updated plan
        "400":
          description: The request or a route override is invalid, or a driver is not active.
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      message:
                        type: string
                        description: The error message.
                      code:
                        type: string
                        description: The error code.
                      param:
                        type: string
                        description: The parameter that caused the error.
                      url:
                        type: string
                        description: The URL with more information about the error.
                    required:
                      - message
                    description: Failed to validate the request
                  - type: object
                    properties:
                      message:
                        type: string
                      code:
                        type: string
                        description: The error code.
                      param:
                        type: string
                      url:
                        type: string
                        description: The URL with more information about the error.
                    required:
                      - message
                      - param
                    description: A provided route override parameter was invalid.
                    title: Route override was invalid
                  - type: object
                    properties:
                      message:
                        type: string
                        enum:
                          - Driver is not active
                      code:
                        type: string
                        enum:
                          - driver_not_active
                      param:
                        type: string
                        description: The parameter that caused the error.
                    required:
                      - message
                      - code
                    description: The driver is not active
                    title: Driver is not active
                description: The request or a route override is invalid, or a driver is not active.
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: The error message.
                  url:
                    type: string
                    description: The URL with more information about the error.
                required:
                  - message
                description: Unauthorized
        "403":
          description: Plan is no longer accessible due to data access restrictions. Upgrade to a plan that supports a longer delivery history period to access it.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    enum:
                      - Plan is no longer accessible due to data access restrictions. Upgrade to a plan that supports a longer delivery history period to access it.
                  code:
                    type: string
                    enum:
                      - plan_inaccessible
                  url:
                    type: string
                    enum:
                      - https://dispatch.spoke.com/paywall
                required:
                  - message
                  - code
                  - url
                description: Plan is no longer accessible due to data access restrictions. Upgrade to a plan that supports a longer delivery history period to access it.
        "404":
          description: The plan, depot, or driver could not be found.
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      message:
                        type: string
                        enum:
                          - Plan not found
                    required:
                      - message
                    description: The provided plan id does not exist
                    title: Plan not found
                  - type: object
                    properties:
                      message:
                        type: string
                        enum:
                          - Depot not found
                    required:
                      - message
                    description: The provided depot id does not exist
                    title: Depot not found
                  - type: object
                    properties:
                      message:
                        anyOf:
                          - type: string
                            enum:
                              - Driver not found
                          - type: string
                    required:
                      - message
                    description: The provided driver id does not exist
                    title: Driver not found
                description: The plan, depot, or driver could not be found.
        "409":
          description: The plan is not writable.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    enum:
                      - Plan is not writable
                  code:
                    type: string
                    enum:
                      - plan_not_writable
                required:
                  - message
                  - code
                description: The plan is not writable.
                title: Plan is not writable
        "412":
          description: Drivers and plans must have the same depot configured
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    enum:
                      - Driver does not share depot with plan
                  param:
                    type: string
                    description: The parameter that caused the error.
                required:
                  - message
                description: Drivers and plans must have the same depot configured
                title: Plan and driver do not share a depot
        default:
          description: The default error model
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: The error message.
                  code:
                    type: string
                    description: The error code.
                  param:
                    type: string
                    description: The parameter that caused the error.
                  url:
                    type: string
                    description: The URL with more information about the error.
                required:
                  - message
                description: The default error model
components:
  schemas:
    dateSchema:
      type: object
      properties:
        day:
          type: integer
          minimum: 1
          maximum: 31
          description: The day of the date.
        month:
          type: integer
          minimum: 1
          maximum: 12
          description: The month of the date.
        year:
          type: integer
          minimum: 2000
          maximum: 2100
          description: The year of the date.
      required:
        - day
        - month
        - year
      additionalProperties: false
      description: A date.
    depotIdSchema:
      type: string
      pattern: ^depots\/[a-zA-Z0-9---_]{1,50}$
    driverIdSchema:
      type: string
      pattern: ^drivers\/[a-zA-Z0-9---_]{1,50}$
    planIdSchema:
      type: string
      pattern: ^plans\/[a-zA-Z0-9---_]{1,50}$
    planSchema:
      type: object
      properties:
        id:
          allOf:
            - $ref: "#/components/schemas/planIdSchema"
          description: The unique identifier of the plan.
        title:
          type: string
          description: The title of the plan.
        starts:
          $ref: "#/components/schemas/dateSchema"
        depot:
          anyOf:
            - $ref: "#/components/schemas/depotIdSchema"
            - type: "null"
          description: The depot ID of the plan, in the format depots/<id>
        distributed:
          type: boolean
          description: Whether the plan has been distributed.
        writable:
          type: boolean
          description: Whether the plan is writable using the normal Plan APIs. If this is false, you will need to use the [Live Plan APIs](/api/live-plans) to edit the plan. Any plan created before 2023-04-01 is not writable.
        optimization:
          anyOf:
            - type: string
              enum:
                - creating
                - editing
                - preview
                - optimized
                - optimizing
            - type: "null"
          description: The optimization state of the plan.
        drivers:
          type: array
          items:
            $ref: "#/components/schemas/driverIdSchema"
          description: The driver IDs of the plan, in the format drivers/<id>.
        routes:
          type: array
          items:
            $ref: "#/components/schemas/routeIdSchema"
          description: The route IDs of the plan, in the format routes/<id>.
        routeOverrides:
          anyOf:
            - type: object
              properties:
                startTime:
                  anyOf:
                    - type: object
                      properties:
                        hour:
                          type: integer
                          minimum: 0
                          maximum: 23
                          description: Hour of the day
                        minute:
                          type: integer
                          minimum: 0
                          maximum: 59
                          description: Minute of the hour
                      required:
                        - hour
                        - minute
                      additionalProperties: false
                      description: Time of day in hours and minutes. Uses a 24 hour clock.
                    - type: "null"
                  description: Plan's start time.
                endTime:
                  anyOf:
                    - type: object
                      properties:
                        hour:
                          type: integer
                          minimum: 0
                          maximum: 23
                          description: Hour of the day
                        minute:
                          type: integer
                          minimum: 0
                          maximum: 59
                          description: Minute of the hour
                      required:
                        - hour
                        - minute
                      additionalProperties: false
                      description: Time of day in hours and minutes. Uses a 24 hour clock.
                    - type: "null"
                  description: Plan's end time.
                startAddress:
                  anyOf:
                    - type: object
                      properties:
                        address:
                          type: string
                          description: The address of the stop.
                        addressLineOne:
                          type: string
                          description: The first line of the address.
                        addressLineTwo:
                          type: string
                          description: The second line of the address.
                        latitude:
                          anyOf:
                            - type: number
                              minimum: -90
                              maximum: 90
                            - type: "null"
                          description: The latitude of the address in decimal degrees.
                        longitude:
                          anyOf:
                            - type: number
                              minimum: -180
                              maximum: 180
                            - type: "null"
                          description: The longitude of the address in decimal degrees.
                        placeId:
                          description: The identifier of the place corresponding to this stop on Google Places
                          type:
                            - string
                            - "null"
                        placeTypes:
                          type: array
                          items:
                            type: string
                          description: Array of strings that is provided by the Google AutoCompleteAPI
                      required:
                        - address
                        - addressLineOne
                        - addressLineTwo
                        - latitude
                        - longitude
                        - placeId
                        - placeTypes
                      additionalProperties: false
                      description: The address of the stop.
                    - type: "null"
                  description: Plan's start location.
                endAddress:
                  anyOf:
                    - type: object
                      properties:
                        address:
                          type: string
                          description: The address of the stop.
                        addressLineOne:
                          type: string
                          description: The first line of the address.
                        addressLineTwo:
                          type: string
                          description: The second line of the address.
                        latitude:
                          anyOf:
                            - type: number
                              minimum: -90
                              maximum: 90
                            - type: "null"
                          description: The latitude of the address in decimal degrees.
                        longitude:
                          anyOf:
                            - type: number
                              minimum: -180
                              maximum: 180
                            - type: "null"
                          description: The longitude of the address in decimal degrees.
                        placeId:
                          description: The identifier of the place corresponding to this stop on Google Places
                          type:
                            - string
                            - "null"
                        placeTypes:
                          type: array
                          items:
                            type: string
                          description: Array of strings that is provided by the Google AutoCompleteAPI
                      required:
                        - address
                        - addressLineOne
                        - addressLineTwo
                        - latitude
                        - longitude
                        - placeId
                        - placeTypes
                      additionalProperties: false
                      description: The address of the stop.
                    - type: "null"
                  description: Plan's end location.
                maxStops:
                  anyOf:
                    - type: integer
                      minimum: -9007199254740991
                      maximum: 9007199254740991
                    - type: "null"
                  description: Maximum number of Stops per route.
                drivingSpeed:
                  anyOf:
                    - type: string
                      enum:
                        - slower
                        - average
                        - faster
                    - type: "null"
                  description: The relative driving speed compared to others.
                deliverySpeed:
                  anyOf:
                    - type: string
                      enum:
                        - slower
                        - average
                        - faster
                    - type: "null"
                  description: The relative delivery speed compared to others.
                vehicleType:
                  anyOf:
                    - type: string
                      enum:
                        - bike
                        - scooter
                        - car
                        - small_truck
                        - truck
                        - electric_cargo_bike
                    - type: "null"
                  description: The vehicle type used for deliveries.
                optimizationSettings:
                  type: object
                  properties:
                    objective:
                      type: string
                      enum:
                        - minimize_drivers
                        - distribute_services
                      description: The primary optimization objective.
                    subObjective:
                      anyOf:
                        - type: string
                          enum:
                            - equalize_workload
                            - equalize_time
                            - maximize_efficiency
                          description: The secondary optimization objective.
                        - type: "null"
                  required:
                    - objective
                  additionalProperties: false
                  description: Optimization settings for the plan.
              required:
                - startTime
                - endTime
                - startAddress
                - endAddress
                - maxStops
                - drivingSpeed
                - deliverySpeed
                - vehicleType
                - optimizationSettings
              additionalProperties: false
              description: Settings for this plan to override default route configurations.
            - type: "null"
          description: Settings for this plan to override default route configurations.
      required:
        - id
        - title
        - starts
        - depot
        - distributed
        - writable
        - optimization
        - drivers
        - routes
        - routeOverrides
      additionalProperties: false
      description: A plan.
    routeIdSchema:
      type: string
      pattern: ^routes\/[a-zA-Z0-9---_]{1,50}$
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
      description: Use the API key as the username and leave the password empty.
````