Skip to main content

Route Calculation

4 API calls in this section.

Endpoints for calculating optimized delivery routes using Google Maps Directions API.

Get Route - Basic​

Delivery & Last-Mile / Route Calculation
GET/route/for-driver/{{driver_id}}/delivery/{{delivery_id}}

Calculate optimized route from driver's stored location to pickup and delivery locations.

  • Requires valid JWT token or API key

  • User must be system admin, dispatcher, tenant admin, or the driver themselves

Authorization

  • System Admins: Full access to all routes

  • Dispatchers/Tenant Admins: Access to routes within their tenant

  • Drivers: Access to their own assigned routes only

Path parameters

ParameterTypeDescription
driver_idRequiredstring

UUID of the driver

delivery_idRequiredstring

UUID of the delivery

Query parameters

ParameterTypeDescription
languageOptionalstring

Preferred language for response messages (default: en)

Example: en

Headers

ParameterTypeDescription
Authorizationstring

JWT token for authentication

Example: Bearer {{access_token}}

Content-Typestring

Example: application/json

Staging
Request
curl
1curl --globoff --request GET "https://staging-api.ondi.io/functions/v1/route/for-driver/${DRIVER_ID}/delivery/${DELIVERY_ID}?language=en" \2  --header "Authorization: Bearer ${ONDI_ACCESS_TOKEN}" \3  --header "Content-Type: application/json"

Response examples

200OK
Response body
json
1{2  "success": true,3  "message": "Route calculated successfully",4  "route": {5    "encoded_polyline": "u{~vFvyys@fS]...",6    "total_distance_meters": 15420,7    "total_duration_seconds": 1800,8    "waypoints": [9      {10        "lat": 40.7128,11        "lng": -74.006,12        "type": "pickup"13      },14      {15        "lat": 40.7589,16        "lng": -73.9851,17        "type": "dropoff"18      }19    ]20  }21}

Get Route - With Current Location​

Delivery & Last-Mile / Route Calculation
GET/route/for-driver/{{driver_id}}/delivery/{{delivery_id}}

Calculate optimized route using driver's real-time location instead of stored location.

  • Requires valid JWT token or API key

  • User must be system admin, dispatcher, tenant admin, or the driver themselves

Use Case

  • When driver's real-time location is more accurate than stored location

  • For live route updates during delivery

  • When driver location hasn't been updated in the database recently

Path parameters

ParameterTypeDescription
driver_idRequiredstring

UUID of the driver

delivery_idRequiredstring

UUID of the delivery

Query parameters

ParameterTypeDescription
current_latstring

Driver's current latitude (-90 to 90)

Example: {{current_lat}}

current_lngstring

Driver's current longitude (-180 to 180)

Example: {{current_lng}}

languageOptionalstring

Preferred language for response messages (default: en)

Example: en

Headers

ParameterTypeDescription
Authorizationstring

JWT token for authentication

Example: Bearer {{access_token}}

Content-Typestring

Example: application/json

Staging
Request
curl
1curl --globoff --request GET "https://staging-api.ondi.io/functions/v1/route/for-driver/${DRIVER_ID}/delivery/${DELIVERY_ID}?current_lat=${CURRENT_LAT}&current_lng=${CURRENT_LNG}&language=en" \2  --header "Authorization: Bearer ${ONDI_ACCESS_TOKEN}" \3  --header "Content-Type: application/json"

Response examples

200OK
Response body
json
1{2  "success": true,3  "message": "Route calculated successfully",4  "route": {5    "encoded_polyline": "u{~vFvyys@fS]...",6    "total_distance_meters": 12350,7    "total_duration_seconds": 1620,8    "waypoints": [9      {10        "lat": 40.7128,11        "lng": -74.006,12        "type": "pickup"13      },14      {15        "lat": 40.7589,16        "lng": -73.9851,17        "type": "dropoff"18      }19    ]20  }21}

Get Route - Basic​

Delivery & Last-Mile / Route Calculation
GET/route/for-driver/{{driver_id}}/delivery/{{delivery_id}}

Calculate optimized route from driver's stored location to pickup and delivery locations.

  • Requires valid JWT token or API key

  • User must be system admin, dispatcher, tenant admin, or the driver themselves

Authorization

  • System Admins: Full access to all routes

  • Dispatchers/Tenant Admins: Access to routes within their tenant

  • Drivers: Access to their own assigned routes only

Path parameters

ParameterTypeDescription
driver_idRequiredstring

UUID of the driver

delivery_idRequiredstring

UUID of the delivery

Query parameters

ParameterTypeDescription
languageOptionalstring

Preferred language for response messages (default: en)

Example: en

Headers

ParameterTypeDescription
Authorizationstring

JWT token for authentication

Example: Bearer {{access_token}}

Content-Typestring

Example: application/json

Staging
Request
curl
1curl --globoff --request GET "https://staging-api.ondi.io/functions/v1/route/for-driver/${DRIVER_ID}/delivery/${DELIVERY_ID}?language=en" \2  --header "Authorization: Bearer ${ONDI_ACCESS_TOKEN}" \3  --header "Content-Type: application/json"

Response examples

200OK
Response body
json
1{2  "success": true,3  "message": "Route calculated successfully",4  "route": {5    "encoded_polyline": "u{~vFvyys@fS]...",6    "total_distance_meters": 15420,7    "total_duration_seconds": 1800,8    "waypoints": [9      {10        "lat": 40.7128,11        "lng": -74.006,12        "type": "pickup"13      },14      {15        "lat": 40.7589,16        "lng": -73.9851,17        "type": "dropoff"18      }19    ]20  }21}

Get Route - With Current Location​

Delivery & Last-Mile / Route Calculation
GET/route/for-driver/{{driver_id}}/delivery/{{delivery_id}}

Calculate optimized route using driver's real-time location instead of stored location.

  • Requires valid JWT token or API key

  • User must be system admin, dispatcher, tenant admin, or the driver themselves

Use Case

  • When driver's real-time location is more accurate than stored location

  • For live route updates during delivery

  • When driver location hasn't been updated in the database recently

Path parameters

ParameterTypeDescription
driver_idRequiredstring

UUID of the driver

delivery_idRequiredstring

UUID of the delivery

Query parameters

ParameterTypeDescription
current_latstring

Driver's current latitude (-90 to 90)

Example: {{current_lat}}

current_lngstring

Driver's current longitude (-180 to 180)

Example: {{current_lng}}

languageOptionalstring

Preferred language for response messages (default: en)

Example: en

Headers

ParameterTypeDescription
Authorizationstring

JWT token for authentication

Example: Bearer {{access_token}}

Content-Typestring

Example: application/json

Staging
Request
curl
1curl --globoff --request GET "https://staging-api.ondi.io/functions/v1/route/for-driver/${DRIVER_ID}/delivery/${DELIVERY_ID}?current_lat=${CURRENT_LAT}&current_lng=${CURRENT_LNG}&language=en" \2  --header "Authorization: Bearer ${ONDI_ACCESS_TOKEN}" \3  --header "Content-Type: application/json"

Response examples

200OK
Response body
json
1{2  "success": true,3  "message": "Route calculated successfully",4  "route": {5    "encoded_polyline": "u{~vFvyys@fS]...",6    "total_distance_meters": 12350,7    "total_duration_seconds": 1620,8    "waypoints": [9      {10        "lat": 40.7128,11        "lng": -74.006,12        "type": "pickup"13      },14      {15        "lat": 40.7589,16        "lng": -73.9851,17        "type": "dropoff"18      }19    ]20  }21}