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

# Update routing result by ID

> The API PUT request for Routing Result by ID serves to update the existing routing result using the provided payload data. This action involves a comprehensive replacement of all present data within the routing result with the new information supplied in the payload. It's important to exercise caution when utilizing this request, as improper handling could lead to unintended data loss. 
 
 In addition to the primary effects, the successful execution of the PUT request triggers an automatic recalculation of the summary associated with the modified routing result. This step ensures that the summary remains synchronized with the updated data, providing an accurate representation of the routing result's current state.



## OpenAPI

````yaml /openapi/public/openapi-routing.json put /result/{resultId}
openapi: 3.0.0
info:
  title: MileApp API - Routing
  version: 3.0.0
  description: MileApp API Documentation - RESTful API for field operations management.
servers:
  - url: https://apiweb.mile.app/api/v3
security:
  - bearerAuth: []
tags:
  - name: Vehicle
    description: >-
      The vehicle represents a car, bike, truck, or other form of transportation
      used in your organization. They are utilized to optimize the route
      planning process, determining the most efficient path for completing
      multiple tasks or visits. The vehicle attributes contain IDs, capacity,
      speed, working hours, tags, and constraints.


      **To see the details of vehicle object, please follow [this
      link](#tag/vehicle_model)**
  - name: Routing
    description: >-
      The **Routing** refers to process of finding the most effective routes for
      vehicles to travel from one visit to another. The optimization process
      will generate a result that could update the respective task data when
      dispatched. With the ability to handle complex constraints and variables
      such as capacity, time windows, and vehicle availability, the API can be
      customized to meet the specific needs of any business or organization.


      **This section is for the v2 of routing api, if you still use the old one,
      please follow [this link](/v1) to see documentation**.


      **Routing results** are collection of route optimization's results that
      already successfully processed and saved in the database. Routing results
      contains list of routed visits and dropped visits.


      1. Routed visits are sequence recommendation of visits/tasks list
      according to most suitable vehicle and best route.

      2. Dropped visits are list of tasks/visits that out of range of the
      calculation.


      **To see the details of routing object, please follow [this
      link](#tag/route_model)**


      ## Why use Route Optimization


      With Route Optimization API, you can establish or refine an automated
      dispatch or route planning process that improves the operational
      efficiency of your transportation needs. With parameters to express your
      unique operational objectives and constraints, and an algorithm built on
      top of the trusted Google Maps data, the service generates the best
      possible route plans to meet those constraints. Some use-case examples
      follow:


      - A **logistics company** uses Route Optimization to optimize the
      assignments of all next-day shipments, providing a route for each shipment
      that optimizes for distance and time efficiency, cost saving, on time
      delivery, and driver and end customer satisfaction.


      - A **field service provider** uses Route Optimization to find the optimal
      route and sequence for technician's service appointments, and re-optimize
      when condition changes occur, such as en route delays.


      - An **on demand food delivery** company uses Route Optimization in their
      real-time dispatch process to choose the best active driver to pick up
      several new orders and insert it in their existing routes.


      - A **medical service provider** uses Route Optimization to map health
      providers to appointments, improving the efficiency of the routes for each
      provider across their day.


      ## How Route Optimization works


      The Route Optimization API uses a number of inputs to return a route plan.
      Inputs include vehicles, visits or shipments, configurations, and
      constraints. A route plan includes tasks assignment to vehicles, the
      multi-stop routes for each vehicle, and the related metrics.
paths:
  /result/{resultId}:
    put:
      tags:
        - Routing
      summary: Update routing result by ID
      description: >-
        The API PUT request for Routing Result by ID serves to update the
        existing routing result using the provided payload data. This action
        involves a comprehensive replacement of all present data within the
        routing result with the new information supplied in the payload. It's
        important to exercise caution when utilizing this request, as improper
        handling could lead to unintended data loss. 
         
         In addition to the primary effects, the successful execution of the PUT request triggers an automatic recalculation of the summary associated with the modified routing result. This step ensures that the summary remains synchronized with the updated data, providing an accurate representation of the routing result's current state.
      operationId: result/id
      parameters:
        - name: resultId
          in: path
          required: true
          description: |-
            Unique identifier for the routing result that generated by system.
            **Example**: `6352736c628401059b37a2e2`
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PUT_ResultRequestUpdate'
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                title: ResultGetSuccess
                properties:
                  status:
                    description: Status of response.
                    type: string
                  data:
                    description: Object of routing result data.
                    type: array
                    items:
                      type: object
                      additionalProperties: true
                example:
                  status: true
                  property:
                    _id: 6352736c628401059b37a2e2
                    name: Result Today
                    result:
                      resultCode: Route-20230801-001
                      routing:
                        - vehicleId: 63da418fc05c0d0269071cf3
                          vehicleName: B001ACB 1
                          assignee: roberto@mile.app
                          workingTime:
                            startTime: '08:00'
                            endTime: '17:00'
                          vehicleTags:
                            - West
                            - Odd
                          isOddEven: true
                          oddEven: even
                          trips:
                            - visitId: hub-635f6ad98e47b604ed5f5e09
                              coordinate: '-6.17148,106.82649'
                              isHub: true
                              weight: 0
                              travelTime: 0
                              visitTime: 0
                              waitingTime: 0
                              eta: '8:00:00'
                              etd: '8:00:00'
                              distance: 0
                              order: 0
                            - visitId: taskId-63994a54e1528d445641d9a2
                              visitName: Visit 1
                              address: Neo Soho, Jakarta Barat
                              coordinate: '-6.261532638313604,106.80685970157342'
                              isHub: false
                              tags:
                                - West
                                - Odd
                              timeWindow:
                                startTime: null
                                endTime: null
                              weight: 0
                              travelTime: 31
                              visitTime: 17
                              waitingTime: 0
                              eta: '8:30:46'
                              etd: '8:47:46'
                              distance: 12817
                              order: 1
                              allowOddEven: true
                            - visitId: hub-635f6ad98e47b604ed5f5e09
                              coordinate: '-6.17148,106.82649'
                              isHub: true
                              weight: 0
                              travelTime: 3
                              visitTime: 0
                              waitingTime: 0
                              eta: '9:41:12'
                              etd: '9:41:12'
                              distance: 974
                              order: 3
                          totalWeight: 0
                          vehicleMaxWeight: 100
                          vehicleMinWeight: 0
                          weightPercentage: 0%
                          fixedCost: 0
                          totalNodes: 3
                          totalVisits: 1
                          speed: 25
                          totalTravelTime: 69
                          totalDistance: 27996
                          totalVisitTime: 34
                          totalWaitingTime: 0
                          totalSpentTime: 103
                      dropped:
                        - id: taskId-63970a49cc6ae973f90929e2
                          name: Visit 2
                          address: Gambir Jakarta
                          coordinate: '-6.17148,106.82649'
                          timeWindow:
                            startTime: null
                            endTime: null
                          visitTime: '20'
                          capacity:
                            weight: 20.12345
                          tags:
                            - 63da418fc05c0d0269071cf2
                          assignedVehicleId: 63da418fc05c0d0269071cf2
                          isHub: false
                          reason: No vehicle with matching tags
                          visitId: taskId-63970a49cc6ae973f90929e2
                          visitName: Visit 2
                      summary:
                        routedVisits: 1
                        droppedVisits: 1
                        totalVisits: 2
                        usedVehicles: 1
                        unusedVehicles: 0
                        totalVehicles: 1
                        totalDistance: 22666
                        totalTravelTime: 34
                        totalVisitTime: 12
                        totalWaitingTime: 0
                        totalSpentTime: 22712
                        minFinishTime: '09:41:12'
                        maxFinishTime: '09:41:12'
                        avgFinishTime: '09:41:12'
                        avgSpeed: 30
                        capacityConstraint:
                          - name: weight
                            optimized: 100
                            available: 300
                            percentage: 33.3
                    hubId: 635f6ad98e47b604ed5f5e09
                    hubCoordinate: '-6.17148,106.82649'
                    configurationId: null
                    configuration:
                      defaultVisitTime: 10
                      defaultSpeed: 15
                      multitrip: false
                      returnToHub: true
                      useAllVehicle: true
                      clustering: false
                      capacityConstraint:
                        - weight
                      name: Configuration Default
                      autoSpeed: false
                      tripsPerVehicle: -1
                      useOddEven: true
                      oddEvenTime:
                        - startTime: '07:00'
                          endTime: '10:00'
                        - startTime: '17:00'
                          endTime: '20:00'
                    routingDate: '2023-08-08'
                    createdTime: '2023-02-06T01:18:36+00:00'
                    resultTotal:
                      routing: 1
                      dropped: 1
                      total: 2
                    organizationId: 635f6a998e47b604ed5f5e02
                    createdBy: 635f6a9a8e47b604ed5f5e08
                    updatedTime: '2023-02-06T06:59:03+00:00'
                    user:
                      name: Marshall Teach
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Bad request - invalid parameters provided.
        '404':
          description: Data not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Data not found
        '500':
          description: Server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Internal server error, please contact support@mile.app.
      deprecated: false
      security:
        - bearerAuth: []
components:
  schemas:
    PUT_ResultRequestUpdate:
      title: PUT/ResultRequestUpdate
      example:
        result:
          routing:
            - vehicleId: 63da418fc05c0d0269071cf3
              vehicleName: B001ACB 1
              assignee: roberto@mile.app
              workingTime:
                startTime: '08:00'
                endTime: '17:00'
              vehicleTags:
                - West
                - Odd
              trips:
                - visitId: hub-635f6ad98e47b604ed5f5e09
                  coordinate: '-6.17148,106.82649'
                  isHub: true
                  weight: 0
                  travelTime: 0
                  visitTime: 0
                  waitingTime: 0
                  eta: '8:00:00'
                  etd: '8:00:00'
                  distance: 0
                  order: 0
                - visitId: taskId-63994a54e1528d445641d9a2
                  visitName: Visit 1
                  address: Neo Soho, Jakarta Barat
                  coordinate: '-6.261532638313604,106.80685970157342'
                  isHub: false
                  tags:
                    - West
                    - Odd
                  timeWindow:
                    startTime: null
                    endTime: null
                  weight: 0
                  travelTime: 31
                  visitTime: 17
                  waitingTime: 0
                  eta: '8:30:46'
                  etd: '8:47:46'
                  distance: 12817
                  order: 1
                - visitId: hub-635f6ad98e47b604ed5f5e09
                  coordinate: '-6.17148,106.82649'
                  isHub: true
                  weight: 0
                  travelTime: 3
                  visitTime: 0
                  waitingTime: 0
                  eta: '9:41:12'
                  etd: '9:41:12'
                  distance: 974
                  order: 3
              totalWeight: 0
              vehicleMaxWeight: 100
              vehicleMinWeight: 0
              weightPercentage: 0%
              speed: 25
              totalTravelTime: 69
              totalDistance: 27996
              totalVisitTime: 34
              totalWaitingTime: 0
              totalSpentTime: 103
          dropped:
            - id: taskId-63970a49cc6ae973f90929e2
              name: Visit 2
              address: Gambir Jakarta
              coordinate: '-6.17148,106.82649'
              timeWindow:
                startTime: null
                endTime: null
              visitTime: '20'
              capacity:
                weight: 20.12345
              tags:
                - 63da418fc05c0d0269071cf2
              assignedVehicleId: 63da418fc05c0d0269071cf2
              isHub: false
              reason: No vehicle with matching tags
              visitId: taskId-63970a49cc6ae973f90929e2
              visitName: Visit 2
      type: object
      required:
        - result
      properties:
        result:
          type: array
          description: >-
            The routing result which includes information about countryCode,
            resultCode, routing details, and dropped results.
          items:
            type: object
            required:
              - startTime
              - endTime
              - multiday
            properties:
              routing:
                type: array
                description: >-
                  A list of vehicles that have successfully undergone route
                  optimization.
                items:
                  type: object
                  properties:
                    vehicleId:
                      description: >-
                        The unique identifier for the vehicle generated by the
                        system. 

                        **Example**: `6352736c628401059b37a2e2`
                      type: string
                    vehicleName:
                      description: >-
                        The name of the vehicle used for reference, such as a
                        number plate or vehicle brand. 

                        **Example**: `B001ACB`
                      type: string
                    vehicleTags:
                      description: >-
                        Tags assigned to the vehicle for route optimization
                        purposes. Visits with matching tags will be assigned to
                        vehicles with the same tags. 

                        **Example**: `['West','Odd']`
                      type: array
                    assignee:
                      description: >-
                        The email address of the worker assigned to the vehicle.
                        Each vehicle can only be assigned to one worker. 

                        **Example**: `roberto@mile.app`
                      type: string
                    speed:
                      description: >-
                        The default average speed of the vehicle. The speed
                        cannot be less than 5 km/h. If not provided, the default
                        value is 25 km/h. 

                        **Example:** `15`
                      type: integer
                    workingTime:
                      description: >-
                        The working hours of the vehicle, including the start
                        time, end time, and whether it spans multiple days. If
                        not provided, the system will use the configuration
                        values for routing purposes. 

                        **Example**:

                        `{`

                        `startTime':'08:00',`

                        `endTime':'17:00`

                        `}`
                      type: array
                      items:
                        type: object
                        additionalProperties: true
                    total{Constraint}:
                      description: >-
                        The sum of constraints for visits routed on this
                        vehicle. **Example:** `100`
                      type: number
                    vehicleMax{Constraint}:
                      description: >-
                        The maximum constraint capacity of this vehicle.
                        **Example:** `200`
                      type: number
                    vehicleMin{Constraint}:
                      description: >-
                        The minimum constraint capacity of this vehicle.
                        **Example:** `50`
                      type: number
                    '{Constraint}Percentage':
                      description: >-
                        The percentage of constraint capacity used by this
                        vehicle. Calculated as
                        **totalConstraint/vehicleMaxConstraint**. 

                        **Example:** `50%`
                      type: string
                    totalTravelTime:
                      description: >-
                        The sum of travel times for visits routed on this
                        vehicle, in minutes. **Example:** `100`
                      type: number
                    totalDistance:
                      description: >-
                        The sum of distances traveled for each visit on this
                        vehicle, in meters. **Example:** `500`
                      type: number
                    trips:
                      description: The list of routed visits for each vehicle.
                      type: array
                      items:
                        type: object
                        properties:
                          visitId:
                            description: |-
                              The unique identifier for the visit. 
                              **Example:** `6311cc36db29775ad01694e6`
                            type: string
                          coordinate:
                            description: >2-
                               coordinates of the visit, used for engine calculations to find distance and travel time between visits. 
                              **Example:**
                              `-6.230815251666679,106.75684387903198`
                            type: string
                          visitName:
                            description: >-
                              The name of the visit, which can be given a
                              descriptive name based on the destination,
                              customer, or other relevant information.  

                              **Example:** `Visit 1`
                            type: string
                          visitAddress:
                            description: |-
                              The location of the visit.  
                              **Example:** `Neo Soho, Jakarta Barat`
                            type: string
                          tags:
                            description: >-
                              Tags associated with the visit. Visits with
                              matching tags will be assigned to vehicles with
                              the same tags.

                              **Example:** `['West', 'Odd']`
                            type: array
                          timeWindow:
                            description: >-
                              The time span during which the visit can be made,
                              specified as opening and closing hours. If not
                              provided, the visit can be made at any time. 

                              If this is not filled then the destination can be
                              visited anytime.  

                              **Example:** `{'startTime': value, 'endTime':
                              value}`
                            type: array
                            items:
                              type: object
                              additionalProperties: true
                          travelTime:
                            description: >-
                              The estimated travel time from the previous trip
                              to the current trip, in minutes. 

                              **Example:** `10`
                            type: integer
                          waitingTime:
                            description: >-
                              The idle time after arriving at the destination.
                              This accounts for activities such as handing over
                              goods, waiting for customers, and parking
                              vehicles. 

                              **Example:** `10`
                            type: integer
                          eta:
                            description: >-
                              The estimated time of arrival at the current
                              trip. 

                              **Example:** `09:34:00` 
                            type: string
                          etd:
                            description: >-
                              The estimated time of departure at the current
                              trip. 

                              **Example:** `09:34:00` 
                            type: string
                          distance:
                            description: >-
                              The distance from the previous trip to the current
                              trip, in meters. 

                              **Example:** `22666`
                            type: string
                          order:
                            description: >-
                              The order of the visit handled by each vehicle's
                              trips. Visits with smaller order values will be
                              served first. 

                              **Example:** `1`
                            type: integer
                          tripOrder:
                            description: >-
                              This field exists only when multitrip is activated
                              and the vehicle handles multiple trips. It
                              distinguishes the list of visits on vehicle trips
                              based on the vehicle's starting point or vehicle's
                              reload from the hub. 

                              **Example:** `1`
                            type: integer
              dropped:
                type: array
                description: >-
                  Collection of trips/visits that can't optimized for some
                  reason (failed to be routed)
                items:
                  type: object
                  properties:
                    id:
                      description: |-
                        The unique identifier for the visit that was dropped. 
                        **Example:** `6311cc36db29775ad01694e6`
                      type: string
                    address:
                      description: |-
                        The location of the dropped visit. 
                        **Example:** `Neo Soho, Jakarta Barat`
                      type: string
                    capacity:
                      description: >-
                        The capacity constraints for the dropped visit, used for
                        route optimization purposes. Each constraint has a
                        maximum value of 9999999999. 

                        **Example:** `{'width': 100, 'height': 150}`
                      type: array
                    coordinate:
                      description: >-
                        The coordinates of the dropped visit, used for engine
                        calculations to find distance and travel time between
                        visits. 

                        **Example:** `-6.230815251666679,106.75684387903198`
                      type: string
                    visitTime:
                      description: >-
                        The idle time after arriving at the destination. This
                        accounts for activities such as handing over goods,
                        waiting for customers, and parking vehicles, based on
                        the specific business needs. 

                        **Example:** `10`
                      type: integer
                    tags:
                      description: >-
                        Tags associated with the dropped visit. Visits with
                        matching tags would have been assigned to vehicles with
                        the same tags. 

                        **Example:** `['West', 'Odd']`
                      type: array
                    reason:
                      description: |-
                        The reason why the visit was dropped. 
                        **Example:** `Dropped due to constraint`
                      type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Use a valid Bearer token to authenticate.

````