Documentation menu
Search docs…⌘K

API reference

Best order to visit a day's stops

Returns the visiting order that minimizes total drive time for up to 100 stops, with road distance and time per leg and in total. Typical use: a sales rep's or rider's daily plan. By default the first stop is the start (e.g. home or depot) and the plan ends at whichever stop is best; use `end: "start"` to come back, or `end: "last"` to finish at the last stop given. Starting and ending anywhere is not supported. Billed as one `optimize` unit per stop.

Endpoint

POSThttps://api.wayline.cloud/v1/optimize
Bearer Auth

Requires an API key (authentication). Product overview: Route Optimization API. Billing: see units & pricing.

Request body

JSON object (OptimizeRequest). Points accept "lat,lng" strings, {lat, lng} objects or [lat, lng] arrays.

Request body fields
FieldTypeDescription
stopsrequiredPoint[]
startstringfirst: the plan starts at stops[0] (home, depot). any: best start.One of: first, anyDefault: first
endstringany: finish wherever is best. last: finish at the last stop given. start: return to the start.One of: any, last, startDefault: any
profilestringOne of: car, driving, motorcycle, bike, motorbike, two_wheeler, bicycle, cyclingDefault: car
unitsstringOne of: metric, imperialDefault: metric
geometrystringOne of: none, polyline, polyline6, geojsonDefault: none

Example

curl -X POST "https://api.wayline.cloud/v1/optimize" \
  -H "Authorization: Bearer $WAYLINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"stops":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478},{"lat":37.8044,"lng":-122.2712}],"end":"start","units":"imperial"}'
Response (example)
{
  "order": [
    0,
    2,
    3,
    1,
    4
  ],
  "legs": [
    {
      "from_index": 0,
      "to_index": 2,
      "distance_meters": 4210,
      "duration_seconds": 540,
      "distance_text": "2.6 mi",
      "duration_text": "9 mins"
    },
    {
      "from_index": 2,
      "to_index": 3,
      "distance_meters": 3010,
      "duration_seconds": 420,
      "distance_text": "1.9 mi",
      "duration_text": "7 mins"
    },
    {
      "from_index": 3,
      "to_index": 1,
      "distance_meters": 6120,
      "duration_seconds": 840,
      "distance_text": "3.8 mi",
      "duration_text": "14 mins"
    },
    {
      "from_index": 1,
      "to_index": 4,
      "distance_meters": 9870,
      "duration_seconds": 1140,
      "distance_text": "6.1 mi",
      "duration_text": "19 mins"
    },
    {
      "from_index": 4,
      "to_index": 0,
      "distance_meters": 19870,
      "duration_seconds": 1260,
      "distance_text": "12.3 mi",
      "duration_text": "21 mins"
    }
  ],
  "returns_to_start": true,
  "total_distance_meters": 43080,
  "total_duration_seconds": 4200,
  "region": "us",
  "map_version": "20261121-2330",
  "profile": "car",
  "units_charged": 5,
  "warnings": []
}

Response

200 — Optimized plan.

Response fields
FieldTypeDescription
orderrequiredinteger[]Input indices in visiting order.
stopsrequiredobject[]Stops in visiting order.
legsrequiredobject[]
returns_to_startrequiredboolean
total_distance_metersrequiredinteger
total_duration_secondsrequiredinteger
total_distance_milesnumber
total_distance_textstring
total_duration_textstring
geometryanyRoute geometry when requested (encoded polyline string or GeoJSON LineString).
units_chargedrequiredinteger
profilerequiredstring
regionrequiredstring
map_versionrequiredstring
warningsrequiredstring[]

Response headers

  • X-Request-Id — Unique identifier for tracking and debugging this request.
  • X-Units-Charged — Billable request units consumed by this request.
  • X-Region — Region code serving this routing request (e.g. `bd`).

Errors

StatusWhen
400Bad request (invalid coordinates, out of coverage, too many elements, etc.).
401Missing or invalid API key, or expired key.
402Free quota exhausted, no payment method, account suspended, or the monthly spend limit you set was reached. Never billed. Raise or remove the limit in the dashboard (Billing) and retry; nothing else changes.
403Account disabled, key IP restriction failed, origin not allowed, or scope not permitted.
404No route found between the requested coordinates.
429Rate limit exceeded or test key daily quota reached.
500Internal server error.
503Upstream routing service temporarily unavailable.

Error bodies contain a code such as OUT_OF_COVERAGE — see the error reference.

Try it

Interactive API Console

POST /v1/optimize

Sends a real request from your browser using a test key (free, never billed). The key stays in this browser tab only.

No key yet? Create a free test key.

Was this page helpful?