---
updatedAt: 2026-09-23T20:14:10.000Z
agentTools:
  projectIndex: https://mediroutes-api.readme.io/llms.txt
---

# Batch Schedule Trips

Runs the batch scheduling algorithm over many trips at once and commits the result: every
route that receives work is saved, exactly as the desktop client's batch schedule window
does. This is the multi-trip counterpart to route/shopTrip + route/saveRoute, and it produces
a batch-optimal answer rather than a series of per-trip ones.
            
This modifies dispatch plans for the whole day being scheduled.
            
Limits, both reported back rather than silently applied:
a request may name at most 500 trips (1000 service ids) and is rejected with 400 above that;
the algorithm is given 120 seconds, after which the request fails with 504 and nothing is
committed - no route is changed.

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "version": "V1",
    "title": "MediroutesAPI V1"
  },
  "paths": {
    "/api/v{version}/batchschedule/trips": {
      "post": {
        "tags": [
          "BatchSchedule"
        ],
        "summary": "Batch Schedule Trips",
        "description": "Runs the batch scheduling algorithm over many trips at once and commits the result: every\r\nroute that receives work is saved, exactly as the desktop client's batch schedule window\r\ndoes. This is the multi-trip counterpart to route/shopTrip + route/saveRoute, and it produces\r\na batch-optimal answer rather than a series of per-trip ones.\r\n            \r\nThis modifies dispatch plans for the whole day being scheduled.\r\n            \r\nLimits, both reported back rather than silently applied:\r\na request may name at most 500 trips (1000 service ids) and is rejected with 400 above that;\r\nthe algorithm is given 120 seconds, after which the request fails with 504 and nothing is\r\ncommitted - no route is changed.",
        "operationId": "batch-schedule-trips",
        "parameters": [
          {
            "name": "api_key",
            "in": "query",
            "description": "Scoping selector for the target transportation provider.",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Authorization",
            "in": "header",
            "description": "access token",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchScheduleRequestModel"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchScheduleRequestModel"
              }
            },
            "application/xml": {
              "schema": {
                "$ref": "#/components/schemas/BatchScheduleRequestModel"
              }
            },
            "text/xml": {
              "schema": {
                "$ref": "#/components/schemas/BatchScheduleRequestModel"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/BatchScheduleRequestModel"
              }
            }
          },
          "description": "Date, the trips to schedule, and the batch options.",
          "required": true
        },
        "responses": {
          "200": {
            "description": "Batch schedule result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchScheduleResultModel"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchScheduleResultModel"
                }
              },
              "application/xml": {
                "schema": {
                  "$ref": "#/components/schemas/BatchScheduleResultModel"
                }
              },
              "text/xml": {
                "schema": {
                  "$ref": "#/components/schemas/BatchScheduleResultModel"
                }
              }
            }
          },
          "400": {
            "description": "Missing or unaligned data. Error message will be returned with response."
          },
          "403": {
            "description": "The api key used does not have access to this resource."
          },
          "404": {
            "description": "A requested service id, or the schedule day, does not exist."
          },
          "504": {
            "description": "The scheduling algorithm exceeded its time limit. Nothing was committed."
          }
        },
        "x-ai-description": "Batch schedules many trips onto routes for one date in a single run of the scheduling algorithm, then SAVES the result: every route that receives trips is updated. Identify trips by the service id of either of their events; all of them must share the service date given in date. Optionally restrict which routes may take work with route_ids. This is the multi-trip counterpart to route/shopTrip - it optimises the whole set together instead of one trip at a time.",
        "x-ai-when-to-use": "The user asks to schedule, batch schedule, auto-schedule or 'build' a day's trips - i.e. more than one trip at once, or 'all the unscheduled trips' for a date. For a single trip, prefer route/shopTrip to review recommendations first and then route/saveRoute. This writes to dispatch plans for many routes at once, so confirm the trip list and the date with the user before calling. Use rides/getRidesByDate with includeUnScheduled=true to find candidate service ids. At most 500 trips (1000 service ids) per call - split larger days into several calls rather than retrying the same oversized one. The algorithm is capped at 120 seconds; if it is exceeded the call fails with 504 and nothing is committed, so a smaller service_ids list or a narrower route_ids is the fix.",
        "x-ai-side-effects": "updates-route",
        "x-ai-returns": "A result object with trips_requested, trips_scheduled, service_ids_not_scheduled, per-trip reasons in unplaced_trips, and a routes array giving each affected route's route_id, route_name, trips_scheduled, total_mileage and whether its save succeeded.",
        "x-ai-required-permission": "dispatch",
        "x-ai-display": {
          "title": "Batch schedule results for {date}",
          "key": "route_id",
          "root": "routes",
          "columns": [
            {
              "field": "route_name",
              "header": "Route"
            },
            {
              "field": "trips_scheduled",
              "header": "Trips Scheduled"
            },
            {
              "field": "total_mileage",
              "header": "Total Miles"
            },
            {
              "field": "saved",
              "header": "Saved"
            }
          ]
        },
        "x-ai-inputs": [
          {
            "name": "date",
            "label": "Date to Schedule",
            "control": "date"
          },
          {
            "name": "service_ids",
            "label": "Trips to Schedule",
            "control": "multiselect",
            "options": {
              "operation": "get-ridesfordate",
              "valueField": "pickup.service_id",
              "labelTemplate": "{rider.last_name}, {rider.first_name} — {pickup.pickup_time} ({status})",
              "args": "date={date};includeUnScheduled=true"
            }
          },
          {
            "name": "route_ids",
            "label": "Routes That May Take Trips (all if empty)",
            "control": "multiselect",
            "options": {
              "operation": "get-routes-by-date",
              "valueField": "route_id",
              "labelTemplate": "{route_name} — {employee_name}",
              "args": "route_date={date}"
            }
          }
        ]
      }
    }
  },
  "servers": [
    {
      "url": "https://api.mediroutes.com"
    }
  ],
  "components": {
    "schemas": {
      "BatchScheduleRequestModel": {
        "description": "Request body for batch scheduling a set of trips onto routes for one service date - the API\r\nequivalent of selecting trips in the desktop client and running its batch schedule window.",
        "type": "object",
        "properties": {
          "date": {
            "format": "date-time",
            "description": "The service date being scheduled. Every trip identified by {SvAPI.Models.BatchScheduleRequestModel.ServiceIdList} must\r\nhave this same service date - a trip can only be scheduled onto routes for its own date.",
            "type": "string"
          },
          "service_ids": {
            "description": "Service ids of the trips to schedule. Either event (pickup or dropoff) of a trip identifies\r\nit; both events always move together. Required, and capped to protect the shared API - see\r\nBatchSchedulingManager.MAX_TRIPS_PER_BATCH.",
            "type": "array",
            "items": {
              "format": "int32",
              "type": "integer"
            }
          },
          "route_ids": {
            "description": "Optional. Restricts the batch to these routes (the desktop's run-selection tab). When\r\nomitted or empty, every eligible route on {SvAPI.Models.BatchScheduleRequestModel.Date} may receive trips. Cancelled\r\nroutes, routes with no vehicle, and the unscheduled placeholder are never eligible.",
            "type": "array",
            "items": {
              "format": "int32",
              "type": "integer"
            }
          },
          "violation_set": {
            "description": "Optional. How strictly scheduling constraints are enforced: batch (default),\r\nsingle (the desktop's single-insert set) or force (most permissive).",
            "type": "string"
          },
          "load_balance": {
            "description": "Optional, defaults to false. When true the algorithm spreads work across the\r\nparticipating routes by capping events per route, exactly as the desktop's Load Balance\r\ncheckbox does.",
            "type": "boolean"
          },
          "mode": {
            "description": "Optional, defaults to batch, which is currently the only supported value.\r\nforce_returns_to_appt_runs and force_to_default_drivers are recognised but\r\nrejected with 400 - see {SvAPI.Models.BatchScheduleMode} for why.",
            "type": "string"
          }
        }
      },
      "BatchScheduleResultModel": {
        "description": "Outcome of a batch-scheduling run: what the algorithm placed, where it was saved, and why\r\nanything was left unscheduled. Mirrors the results grid the desktop client shows after a batch,\r\nplus the per-trip rejection reasons the desktop only writes to its own diagnostics.",
        "type": "object",
        "properties": {
          "trips_requested": {
            "format": "int32",
            "description": "Number of distinct trips identified by the requested service ids.",
            "type": "integer"
          },
          "trips_scheduled": {
            "format": "int32",
            "description": "Number of requested trips the algorithm placed on a real route. A trip left on the\r\nunscheduled placeholder does not count as scheduled.",
            "type": "integer"
          },
          "service_ids_not_scheduled": {
            "description": "The requested service ids whose trips were not placed on any route.",
            "type": "array",
            "items": {
              "format": "int32",
              "type": "integer"
            }
          },
          "unplaced_trips": {
            "description": "One entry per requested trip that could not be placed, with the algorithm's reason where it\r\nreported one. Useful for explaining a partial batch without re-running it.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BatchScheduleUnplacedTripModel"
            }
          },
          "routes": {
            "description": "The routes that received at least one requested trip, and how each save went.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BatchScheduleRouteResultModel"
            }
          },
          "all_routes_saved": {
            "description": "False when at least one affected route failed to save. The algorithm result is still\r\nreported, so a caller can see exactly which routes did and did not persist.",
            "type": "boolean"
          },
          "candidate_route_count": {
            "format": "int32",
            "description": "Number of routes that participated in the run as scheduling candidates.",
            "type": "integer"
          },
          "mode": {
            "description": "The mode that ran, echoed back so the caller can confirm what was applied.",
            "type": "string"
          },
          "violation_set": {
            "description": "The violation set that was applied, echoed back.",
            "type": "string"
          },
          "load_balance": {
            "description": "Whether load balancing was applied.",
            "type": "boolean"
          },
          "max_events_per_run": {
            "format": "int32",
            "description": "The per-route event cap load balancing computed, or null when load balancing was off.\r\nReported because it materially changes how trips get distributed.",
            "type": "integer"
          },
          "elapsed_seconds": {
            "format": "double",
            "description": "Wall-clock seconds the scheduling algorithm ran for.",
            "type": "number"
          }
        }
      },
      "BatchScheduleUnplacedTripModel": {
        "description": "A requested trip the algorithm could not place, with the reason it reported.",
        "type": "object",
        "properties": {
          "trip_guid": {
            "format": "uuid",
            "description": "The trip's MediRoutes trip guid.",
            "type": "string",
            "example": "00000000-0000-0000-0000-000000000000"
          },
          "service_ids": {
            "description": "The requested service ids belonging to this trip.",
            "type": "array",
            "items": {
              "format": "int32",
              "type": "integer"
            }
          },
          "reason": {
            "description": "Why the trip was rejected (capacity, on-board time, scheduled too early/late, no eligible\r\nroute, force failed...). Null when the algorithm reported no reason for this trip.",
            "type": "string"
          },
          "stage": {
            "description": "The algorithm stage the rejection happened at, when reported.",
            "type": "string"
          },
          "detail": {
            "description": "Any extra detail the algorithm attached to the rejection.",
            "type": "string"
          }
        }
      },
      "BatchScheduleRouteResultModel": {
        "description": "One route that received trips in a batch run, with the ordered service ids written to it.",
        "type": "object",
        "properties": {
          "route_id": {
            "format": "int32",
            "description": "The route (run) id.",
            "type": "integer"
          },
          "route_name": {
            "description": "The route's display name.",
            "type": "string"
          },
          "trips_scheduled": {
            "format": "int32",
            "description": "Number of requested TRIPS placed on this route. Note this is a trip count, not the raw\r\npickup/dropoff event count the desktop's results grid shows in its per-run column.",
            "type": "integer"
          },
          "total_mileage": {
            "format": "double",
            "description": "The route's total estimated mileage after the batch, as the desktop reports it.",
            "type": "number"
          },
          "service_ids": {
            "description": "Every pickup/dropoff service id now on this route, in the algorithm's event order. Order is\r\nsignificant: it is the sequence the route is saved with.",
            "type": "array",
            "items": {
              "format": "int32",
              "type": "integer"
            }
          },
          "saved": {
            "description": "Whether this route's save succeeded.",
            "type": "boolean"
          },
          "save_message": {
            "description": "The message returned by the route save - the failure reason when {SvAPI.Models.BatchScheduleRouteResultModel.Saved} is\r\nfalse, otherwise the success message.",
            "type": "string"
          }
        }
      }
    }
  },
  "x-readme": {
    "explorer-enabled": true,
    "proxy-enabled": true
  }
}
```