Skip to content
GuidesPlaygroundDashboard

Optimize route through waypoints

client.optimize.create(OptimizeCreateParams { waypoints, mode, roundtrip } body, RequestOptionsoptions?): OptimizeResult
POST/api/v1/optimize

Optimize route through waypoints

ParametersExpand Collapse
body: OptimizeCreateParams { waypoints, mode, roundtrip }
waypoints: GeoJsonGeometry { coordinates, type }

Waypoints to visit (GeoJSON MultiPoint geometry, minimum 2 points)

coordinates: Array<number> | Array<Array<number>> | Array<Array<Array<number>>> | Array<Array<Array<Array<number>>>>

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array<number>
Array<Array<number>>
Array<Array<Array<number>>>
Array<Array<Array<Array<number>>>>
type: "Point" | "LineString" | "Polygon" | 3 more
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
mode?: "auto" | "foot" | "bicycle"

Travel mode (default: auto)

One of the following:
"auto"
"foot"
"bicycle"
roundtrip?: boolean

Whether route returns to start (default: true)

ReturnsExpand Collapse
OptimizeResult = OptimizeCompletedResult { geometry, properties, status, type } | OptimizeProcessingResult { job_id, status }

Optimization response — either a completed GeoJSON Feature route or an async job reference

One of the following:
OptimizeCompletedResult { geometry, properties, status, type }

Completed optimization — GeoJSON Feature with optimized route

geometry: GeoJsonGeometry { coordinates, type }
coordinates: Array<number> | Array<Array<number>> | Array<Array<Array<number>>> | Array<Array<Array<Array<number>>>>

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array<number>
Array<Array<number>>
Array<Array<Array<number>>>
Array<Array<Array<Array<number>>>>
type: "Point" | "LineString" | "Polygon" | 3 more
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
properties: Properties { distance, duration, waypoint_order }
distance?: number

Total distance in meters

duration?: number

Estimated duration in seconds

waypoint_order?: Array<number>

Optimized waypoint ordering

status: "completed"

Job status

type: "Feature"
OptimizeProcessingResult { job_id, status }

Async optimization in progress — poll with the job_id

job_id: string

Job ID for polling

status: "processing"

Job status

Optimize route through waypoints

import Plaza from '@plazafyi/sdk';

const client = new Plaza({
  apiKey: process.env['PLAZA_API_KEY'], // This is the default and can be omitted
});

const optimizeResult = await client.optimize.create({
  waypoints: { coordinates: [0], type: 'Point' },
});

console.log(optimizeResult);
Returns Examples