Route Optimization API3
## Quickstart
The Route Optimization API can be used to solve [traveling salesman](https://en.wikipedia.org/wiki/Travelling_salesman_problem) or [vehicle routing problems](https://en.wikipedia.org/wiki/Vehicle_routing_problem).
Solve your first problem by following these steps. If you already have a GraphHopper account, start with step 2.
1. [Sign up for GraphHopper](https://support.graphhopper.com/a/solutions/articles/44001976025)
2. [Create an API key](https://support.graphhopper.com/a/solutions/articles/44001976027)
3. Download [simple traveling salesman problem](https://gist.github.com/oblonski/fb2f2be534c3ebe7bebaa72151194182) and save it in a local folder
4. Open your command line, go to that local folder and use cURL ([What is cURL?](https://de.wikipedia.org/wiki/CURL)) as follows:
```
curl -X POST -H "Content-Type: application/json" "https://graphhopper.com/api/1/vrp?key=YOUR_CREATED_API_KEY" --data "@tsp.json"
```
Alternatively, you can use our Editor to explore that API:
1. Login to your GraphHopper account
2. Go to **Editor**
3. Click the **Optimize** button to solve your first problem
4. Analyze the solution on the **Map** or as raw **JSON Output**
If you have successfully solved the first problem, we recommend this tutorial - [Getting Started with the Optimization API](https://www.graphhopper.com/blog/2019/05/17/getting-started-with-the-optimization-api-traveling-salesman-problem/).
It shows and describes the essential elements to model your vehicle routing problem.
To explore the full specification, we recommend that you either use our [route editor](https://www.graphhopper.com/blog/2015/07/21/graphhoppers-new-route-optimization-editor/),
which you can find in our [dashboard](https://graphhopper.com/dashboard/),
or use a REST client such as Insomnia or Postman, as described [here](https://docs.graphhopper.com/#section/Explore-our-APIs/Insomnia).
## Tutorials
We provide [a number of tutorials](https://www.graphhopper.com/tutorial/) illustrating how to use the Route Optimization API and
how to model your vehicle routing problems:
- [Getting Start with the Optimization API - Traveling Salesman Problem](https://www.graphhopper.com/blog/2019/05/17/getting-started-with-the-optimization-api-traveling-salesman-problem/)
- [How to solve a traveling salesman problem with a week-planning horizon?](https://www.graphhopper.com/blog/2020/07/15/how-to-solve-a-traveling-salesman-problem-with-a-week-planning-horizon-and-driver-shifts/)
- [How to schedule technicians with skills and multiple dependencies between tasks?](https://www.graphhopper.com/blog/2016/06/03/how-to-route-technicians-with-skills-and-multiple-dependencies-between-tasks/)
- [What is the difference between the min. of completion time and min. transport time?](https://www.graphhopper.com/blog/2016/06/20/what-is-the-difference-between-the-minimization-of-completion-time-and-minimizing-transport-time/)
- [How to model multiple delivery routes with a single vehicle?](https://www.graphhopper.com/blog/2016/07/21/how-to-model-multiple-delivery-routes-with-a-single-vehicle/)
POST/vrpPOST route optimization problem
Request bodyapplication/json — Request (required)
Responses| Status | Description | Schema |
|---|
200 | A response containing the solution | Response |
400 | Error occurred when reading the request. Request is invalid. | BadRequest |
500 | Error occurred on server side. | InternalErrorMessage |
POST/vrp/optimizePOST route optimization problem (batch mode)
Request bodyapplication/json — Request (required)
Responses| Status | Description | Schema |
|---|
200 | A jobId you can use to retrieve your solution from the server - see solution endpoint. | JobId |
400 | Error occurred when reading client request. Request is invalid. | BadRequest |
500 | Error occurred on server side. | InternalErrorMessage |
GET/vrp/solution/{jobId}GET the solution (batch mode)
Parameters| Name | In | Required | Type |
|---|
jobId | path | yes | string |
Responses| Status | Description | Schema |
|---|
200 | A response containing the solution | Response |
400 | Error occurred on client side such as invalid input. | BadRequest |
404 | Requested solution could not be found. | — |
500 | Error occurred on server side. | — |
Routing API3
### Introduction

The Routing API is part of the GraphHopper Directions API. Routing is the process of finding the best path connecting
two or more points, where the meaning of ''best'' depends on the vehicle and use case.
### Navigation
If you plan to use the Routing API for navigation, have a look at our [open source demo navigation application](https://github.com/graphhopper/graphhopper-navigation-example) and adapt it to your needs.
### Fast
To get started using this API, just provide two or more points and retrieve the fastest route through the road
network that connects them. This type of request is heavily optimized for query performance, so it does not
allow for some advanced features.
### Flexible
Unlock further flexible features via `ch.disable=true`.
GET/routeGET Route Endpoint
Parameters| Name | In | Required | Type |
|---|
point | query | yes | array |
point_hint | query | no | array |
snap_prevention | query | no | array |
vehicle | query | no | — |
curbside | query | no | array |
turn_costs | query | no | boolean |
locale | query | no | string |
elevation | query | no | boolean |
details | query | no | array |
optimize | query | no | string |
instructions | query | no | boolean |
calc_points | query | no | boolean |
debug | query | no | boolean |
points_encoded | query | no | boolean |
ch.disable | query | no | boolean |
weighting | query | no | string |
heading | query | no | array |
heading_penalty | query | no | integer |
pass_through | query | no | boolean |
block_area | query | no | string |
avoid | query | no | string |
algorithm | query | no | string |
round_trip.distance | query | no | integer |
round_trip.seed | query | no | integer |
alternative_route.max_paths | query | no | integer |
alternative_route.max_weight_factor | query | no | number |
alternative_route.max_share_factor | query | no | number |
Responses| Status | Description | Schema |
|---|
200 | Routing Result | RouteResponse |
400 | Your request is not valid. For example, you specified too few or too many points. | GHError |
401 | Authentication necessary | GHError |
429 | API limit reached. | GHError |
500 | Internal server error. We get notified automatically and fix this asap. | GHError |
501 | Only a special list of vehicles is supported. | GHError |
POST/routePOST Route Endpoint
Request bodyapplication/json — RouteRequest
Responses| Status | Description | Schema |
|---|
200 | Routing Result | RouteResponse |
400 | Your request is not valid. For example, you specified too few or too many points. | GHError |
401 | Authentication necessary | GHError |
429 | API limit reached. | GHError |
500 | Internal server error. We get notified automatically and fix this asap. | GHError |
501 | Only a special list of vehicles is supported. | GHError |
GET/route/infoCoverage information
Responses| Status | Description | Schema |
|---|
200 | Coverage Information | InfoResponse |
Matrix API4
### Introduction

The Matrix API is part of the [GraphHopper Directions API](https://graphhopper.com/#directions-api) and with
it you can calculate many-to-many distances and times a lot more efficient than calling the
Routing API multiple times.
In the [Routing API](#tag/Routing-API) we support multiple points, so called 'via points', which results in one
route being calculated. The Matrix API results in NxM routes, or more precise NxM distances or times being calculated
but [is a lot faster](https://www.graphhopper.com/blog/2019/06/04/incredibly-fast-distance-matrix-calculations-with-graphhopper/)
compared to NxM single requests.
The most simple example is a tourist trying to decide
which pizza is close to her instead of using beeline distance she can calculate a 1x4 matrix. Or a delivery service
often in the need of big NxN matrices to solve vehicle routing problems. For example the [GraphHopper Route Optimization API](#tag/Route-Optimization-API)
uses the Matrix API under the hood to achieve this.
Some other use cases for the Matrix API:
* Logistic problems often pick up many items from and deliver them to many locations.
* Calculating detours with many possible points in-between and selecting the best e.g. interesting for ridesharing or taxi applications. For this 1-to-many requests are necessary.
* Finding the best tour for a tourist in the need to visit as many points of interests as possible.
* ...
### API Clients and Examples
See the [clients](#section/API-Clients) section in the main document and [live examples](https://graphhopper.com/api/1/examples/#matrix).
### Description
The Matrix API calculates the well known distance-matrix for a set of points, i.e. it calculates all the distances
between every point combination. But we do not stop there, we also offer a time-, weight- and route-matrix.
The weight-matrix can be used as raw input for e.g. a vehicle routing problem ([VRP](http://en.wikipedia.org/wiki/Vehicle_routing_problem))
and is more precise than a time- or distance-matrix. E.g. for bike routes the actual weight of a route (e.g. the "beauty")
is what you want to decide if a route is 'better' and not always the taken time or distance.
A simple illustration for a 3x3 matrix with identical from and to points:
- |to_point1|to_point2|to_point3
:-----------|:--------|:--------|:--------
from_point1 |0 |1->2 | 1->3
from_point2 |2->1 |0 | 2->3
from_point3 |3->1 |3->2 | 0
A simple illustration for a 1x3 matrix with different start- and end-points:
- | to_point1 | to_point2 | t_point3
:-----------|:-----------|:----------|:--------
from_pointA |A->1 |A->2 |A->3
For every route 1->2, 1-3, ... or A->1,A->2,A->3 you can return only the weight, the time and the distance.
To calculate full routes you can use the [Routing API](#tag/Routing-API).
### Limits and Counts
The cost for one request depends on the number of locations and is documented [here](https://support.graphhopper.com/support/solutions/44000303787#what-is-one-credit).
One request should not exceed the Matrix API location limit, which depends on the subscription, see the
pricing tab in our dashboard.
GET/matrixGET Matrix Endpoint
Parameters| Name | In | Required | Type |
|---|
point | query | no | array |
from_point | query | no | array |
to_point | query | no | array |
point_hint | query | no | array |
from_point_hint | query | no | array |
to_point_hint | query | no | array |
snap_prevention | query | no | array |
curbside | query | no | array |
from_curbside | query | no | array |
to_curbside | query | no | array |
out_array | query | no | array |
vehicle | query | no | — |
fail_fast | query | no | boolean |
turn_costs | query | no | boolean |
Responses| Status | Description | Schema |
|---|
200 | Matrix API response | MatrixResponse |
default | Unexpected Error | GHError |
POST/matrixPOST Matrix Endpoint
Request bodyapplication/json
Responses| Status | Description | Schema |
|---|
200 | Matrix API response | MatrixResponse |
default | Unexpected Error | GHError |
POST/matrix/calculateBatch Matrix Endpoint
Request bodyapplication/json
Responses| Status | Description | Schema |
|---|
200 | A jobId you can use to retrieve your solution from the server. | JobId |
default | Unexpected Error | GHError |
GET/matrix/solution/{jobId}GET Batch Matrix Endpoint
Parameters| Name | In | Required | Type |
|---|
jobId | path | yes | string |
Responses| Status | Description | Schema |
|---|
200 | A response containing the matrix | MatrixResponse |
default | Unexpected Error | GHError |
Geocoding API1
Everything about geocoding
GET/geocodeGeocoding Endpoint
Parameters| Name | In | Required | Type |
|---|
q | query | no | string |
locale | query | no | string |
limit | query | no | integer |
reverse | query | no | boolean |
debug | query | no | boolean |
point | query | no | string |
provider | query | no | string |
Responses| Status | Description | Schema |
|---|
200 | An array found locations | GeocodingResponse |
default | Unexpected error | GHError |
Isochrone API1
Everything about isochrones
GET/isochroneIsochrone Endpoint
Parameters| Name | In | Required | Type |
|---|
point | query | yes | string |
time_limit | query | no | integer |
distance_limit | query | no | integer |
vehicle | query | no | — |
buckets | query | no | integer |
reverse_flow | query | no | boolean |
weighting | query | no | string |
Responses| Status | Description | Schema |
|---|
200 | Isochrone Result | IsochroneResponse |
default | Unexpected Error | GHError |
Map Matching API1
Everything about map matching aka "snap to road"
POST/matchMap-match a GPX file
Parameters| Name | In | Required | Type |
|---|
gps_accuracy | query | no | integer |
vehicle | query | no | string |
Responses| Status | Description | Schema |
|---|
200 | Routing Result | RouteResponse |
default | Unexpected Error | GHError |
Cluster API3
### Introduction

It solves the “capacity clustering problem” by assigning a set of customers to a given number of distinct groups (called clusters).
The API “clusters” by minimizing the total distance from each individual customer to its designated group median.
It can also consider minimum and maximum capacity restrictions for each group.
Clustering can be used in many practical applications.
For example, it can help to plan territories, i.e. territory optimization for field teams with large territories for field workers,
or to solve large vehicle routing problems (VRP).
POST/clusterPOST Cluster Endpoint
Request bodyapplication/json — ClusterRequest (required)
Responses| Status | Description | Schema |
|---|
200 | A response containing the solution | ClusterResponse |
400 | Error occurred when reading the request. Request is invalid. | BadRequest |
500 | Error occurred on server side. | InternalErrorMessage |
POST/cluster/calculateBatch Cluster Endpoint
Request bodyapplication/json — ClusterRequest (required)
Responses| Status | Description | Schema |
|---|
200 | A jobId you can use to retrieve your solution from the server - see solution endpoint. | JobId |
400 | Error occurred when reading client request. Request is invalid. | BadRequest |
500 | Error occurred on server side. | InternalErrorMessage |
GET/cluster/solution/{jobId}GET Batch Solution Endpoint
Parameters| Name | In | Required | Type |
|---|
jobId | path | yes | string |
Responses| Status | Description | Schema |
|---|
200 | A response containing the solution | ClusterResponse |
400 | Error occurred on client side such as invalid input. | BadRequest |
404 | Requested solution could not be found. | — |
500 | Error occurred on server side. | — |