Synchronous Matrix
Purpose
This endpoint enables the submission of a new matrix job for synchronous processing, which is best suited for fast, small matrices of lightweight route calculations. To calculate larger matrix jobs/heavy route calculations please see the Asynchronous endpoint.
API Limitations
- Freemium and Pay as you grow pricing plans support up to 200 items (the number of origins multiplied by the number of destinations) in a single matrix.
- Enterprise pricing plan supports up to 2500 items in a single matrix.
- Matrices don't need to be square.
Max matrix size | Max number of origins | Max number of destinations | Additional limits |
---|---|---|---|
100 | 100 | 100 | N/A |
200 | 200 | 200 |
|
2500 | 1000 | 1000 |
|
Check our Pricing and Contact Sales for quotas tailored based on your needs.
Types
The following data table describes the complex data types that can be used in the Matrix Routing v2 service.
Type | Description |
---|---|
| Latitude, longitude pair (in EPSG:4326 projection), with the following constraints:
Example:
|
| A date and time specified in
RFC 3339
format with an optional time zone offset.
|
Request data
HTTPS method: POST
- Constants and parameters enclosed in curly brackets { } must be replaced with their values.
- Please see the following Request parameters section with the required and optional parameters tables for their values. The generic request format is as follows.
URL request format
All of the following parameters are required:
https://{baseURL}/routing/matrix/{versionNumber}?key={Your_API_Key}
curl command request format
curl -XPOST 'https://{baseURL}/routing/matrix/{versionNumber}?key={Your_API_Key}'
Example
https://api.tomtom.com/routing/matrix/2?key={Your_API_Key}
Request headers
The following table describes HTTP request headers of particular interest to Synchronous Matrix Routing v2 service clients.
Required headers | Description |
---|---|
Content-Type | Specifies the MIME type of the body of the request. |
Optional headers | Description |
---|---|
Tracking-ID | Specifies an identifier for the request.
Value: An |
Request parameters
The following table describes the request parameters.
- Required parameters must be used or the call will fail.
- A parameter's data type is beneath its name.
Required parameters | Description |
---|---|
| Base URL for calling the API.
|
| Service version. |
| An API Key valid for the requested service. |
POST body
The POST body of a matrix request should contain a set of items which will be used to calculate a matrix of route summaries.
1{2 "origins": [3 {4 "point": {"latitude": latitudeValue, "longitude": longitudeValue}5 },6 ...,7 {8 "point": {"latitude": latitudeValue, "longitude": longitudeValue}9 }10 ],11 "destinations": [12 {13 "point": {"latitude": latitudeValue, "longitude": longitudeValue}14 },15 ...,16 {17 "point": {"latitude": latitudeValue, "longitude": longitudeValue}18 }19 ],20 "options": {21 "departAt": dateTime | "any" | "now",22 "arriveAt": dateTime | "any",23 "routeType": "fastest",24 "traffic": "historical" | "live",25 "travelMode": "car" | "truck" | "pedestrian",26 "vehicleMaxSpeed": integer,27 "vehicleWeight": integer,28 "vehicleAxleWeight": integer,29 "vehicleLength": float,30 "vehicleWidth": float,31 "vehicleHeight": float,32 "vehicleCommercial": boolean,33 "vehicleLoadType": [ string, ... ],34 "vehicleAdrTunnelRestrictionCode": string,35 "avoid": [ string, ... ]36 }37}
POST body fields
This section contains the detailed description of allowed fields in the POST body.
Required fields | Description |
---|---|
| A non-empty list of origin locations represented by points. |
| A non-empty list of destination locations represented by points. |
Mutually exclusive fields | Description |
---|---|
| The date and time of departure from the origin point.
Default value:
|
| The date and time of arrival at the destination point.
Values:
|
| Decides how traffic is considered for computing routes.
|
Optional fields | Description |
---|---|
| The type of route requested:
Note: Only the |
| The mode of travel for the requested route. |
| Maximum speed of the vehicle in kilometers/hour.
Default value: |
| Weight of the vehicle in kilograms. A value of |
| Weight per axle of the vehicle in kilograms. A value of |
| Length of the vehicle in meters. A value of |
| Width of the vehicle in meters. A value of |
| Height of the vehicle in meters. A value of |
| Vehicle is used for commercial purposes and thus may not be allowed to
drive on some roads. |
| Specifies types of cargo that may be classified as hazardous materials
and are restricted from some roads.
Use these values for routing in the USA:
Use these values for routing in all other countries:
Note: The
|
| If
Note: The
|
| Specifies something that the route calculation should try to avoid when
determining the route.
|
POST body example
1{2 "origins": [3 {4 "point": { "latitude": 45.458545, "longitude": 9.15049 }5 },6 {7 "point": { "latitude": 45.403337, "longitude": 11.050541 }8 }9 ],10 "destinations": [11 {12 "point": { "latitude": 48.149853, "longitude": 11.499931 }13 },14 {15 "point": { "latitude": 50.033688, "longitude": 14.538226 }16 }17 ],18 "options": {19 "departAt": "2022-12-19T16:39:57",20 "traffic": "historical",21 "travelMode": "truck",22 "vehicleMaxSpeed": 90,23 "vehicleWeight": 12000,24 "vehicleAxleWeight": 4000,25 "vehicleLength": 13.6,26 "vehicleWidth": 2.42,27 "vehicleHeight": 2.4,28 "vehicleCommercial": true,29 "vehicleLoadType": ["otherHazmatExplosive", "otherHazmatGeneral"],30 "vehicleAdrTunnelRestrictionCode": "C",31 "avoid": ["unpavedRoads"]32 }33}
Response data
Synchronous Matrix response
On a successful matrix request submission, the Synchronous Matrix Routing v2 service responds with an HTTP 200
. The response is streamed to the client.
HTTP Status codes
Code | Meaning & possible causes |
---|---|
200 | OK: Request successful. At least one of the route calculations has completed for the requested origins and destinations before the sync request timeout passed. Results are streamed to the client. |
400 | Bad Request: Request cannot be processed correctly, because parameters did not pass validation e.g., due to invalid options, size or header values. |
403 | Forbidden: The API Key is missing, inactive, invalid, not entitled to use Matrix Routing v2 API, or exceeded the available quota. This can also occur when using HTTP instead of HTTPS. |
404 | Not Found: The requested resource could not be found. |
405 | Method Not Allowed: The client used an HTTP method other than POST. |
408 | Request timeout: None of the route calculations completed before the sync request timeout passed. Please retry. If the issue persists, route calculations may be too heavy for the Synchronous endpoint - consider using the Asynchronous endpoint instead, or try splitting into smaller matrices and re-calculate. |
414 | Requested URI is too long: Indicates that the URI requested by the client is longer than the server is willing to interpret. |
415 | Unsupported Media Type: The client used an unsupported media type. |
429 | Too Many Requests: Customer key's quota was exceeded. Please retry later. To increase the key's quota please Contact Sales for values tailored based on your needs. |
500 | An error occurred while processing the request. Please try again later. |
502 | Internal network connectivity issue. Please try again later. |
503 | Service currently unavailable. Please try again later. |
504 | Internal network connectivity issue or a request that has taken too long to complete. Please try again later. |
596 | Service not found. Request contains an incorrect FQDN and/or path. |
Response headers
The following table lists HTTP response headers of particular interest to the Synchronous Matrix Routing v2 service clients.
Header | Description |
---|---|
Access-Control-Expose-Headers | A comma separated list of HTTP header names that browsers are allowed to
access. |
Access-Control-Allow-Origin | A header instructing browsers to allow customer websites to contact the
Matrix Routing v2 service. |
Content-Encoding | The Synchronous Matrix Routing v2 service applies gzip compression to
the response if it is requested by the client with the Accept-Encoding
header. |
Content-Type | The format of the response. |
Tracking-ID | An identifier for the request.
Value: An |
Successful response
1HTTP 200 OK2{3 "data": [4 {5 "originIndex": integer,6 "destinationIndex": integer,7 "routeSummary": {8 "lengthInMeters": integer,9 "travelTimeInSeconds": integer,10 "trafficDelayInSeconds": integer,11 "departureTime": dateTime,12 "arrivalTime": dateTime13 },14 "detailedError": object15 },16 ...17 ],18 "statistics": {19 "totalCount": integer,20 "successes": integer,21 "failures": integer,22 "failureDetails": [23 {24 "code": string,25 "count": integer26 },27 ...28 ]29 }30}
1HTTP 200 OK2{3 "data": [4 {5 "originIndex": 0,6 "destinationIndex": 0,7 "routeSummary": {8 "lengthInMeters": 681999,9 "travelTimeInSeconds": 25106,10 "trafficDelayInSeconds": 1769,11 "departureTime": "2018-08-10T10:20:42+02:00",12 "arrivalTime": "2018-08-10T17:19:07+02:00"13 }14 },15 {16 "originIndex": 0,17 "destinationIndex": 1,18 "detailedError": {19 "code": "CELL_PROCESSING_ERROR",20 "message": "Cell could not be processed",21 "innerError": {22 "code": "MAP_MATCHING_FAILURE",23 "message": "Engine error while executing route request: MAP_MATCHING_FAILURE: Destination (2.2, 2.2)"24 }25 }26 },27 {28 "originIndex": 0,29 "destinationIndex": 2,30 "detailedError": {31 "code": "CELL_PROCESSING_ERROR",32 "message": "Cell could not be processed",33 "innerError": {34 "code": "UNKNOWN",35 "message": "Unknown error occurred"36 }37 }38 }39 ],40 "statistics": {41 "totalCount": 3,42 "successes": 1,43 "failures": 2,44 "failureDetails": [45 {46 "code": "MAP_MATCHING_FAILURE",47 "count": 148 },49 {50 "code": "UNKNOWN",51 "count": 152 }53 ]54 }55}
Successful response fields
Primary fields | |
---|---|
Field | Description |
| Contains all calculated route summaries for this matrix.
Compared to the matrix submission body structure which is
two-dimensional, the |
| Contains information about statistics for this matrix. |
data array | |
Field | Description |
| Zero-based index of the origin of a route. |
| Zero-based index of the destination of a route. |
| Optional field containing the result of a successful route summary calculation. |
| Element of |
| Element of |
| Element of
|
| Element of
|
| Element of
|
| Optional field, present in an HTTP 200 response body only when there was
a problem processing a matrix cell. This field describes the details of
a failure, per matrix cell. It is possible that the whole synchronous
matrix job may be completed with result having an HTTP 200 status while
at the same time multiple, or even all the cells have failed. |
statistics object | |
Field | Description |
| Total number of routes within this matrix. |
| Number of successful routes within this matrix. |
| Number of failed routes within this matrix. |
| When there are any failed cells, this field contains the details about
the failure(s). |
failureDetails array | |
Field | Description |
| One of the defined error codes. |
| Number of failed route calculations within this matrix caused by errors
having given |
Error response
1{2 "detailedError": {3 "code": string,4 "message": string,5 "details": [6 {7 "code": string,8 "message": string,9 "target": string,10 "details": [11 ...12 ],13 "innerError": {14 "code": string,15 "message": string,16 "innerError": {17 ...18 }19 }20 },21 ...22 ]23 }24}
1HTTP 400 BAD REQUEST2{3 "detailedError": {4 "code": "BAD_REQUEST",5 "message": "Bad Request",6 "details": [7 {8 "code": "BAD_ARGUMENT",9 "message": "Error(s) detected in POST body",10 "target": "postBody",11 "details": [12 {13 "code": "BAD_ARGUMENT",14 "message": "Ship is not a valid enum value",15 "target": "postBody:#/options/travelMode"16 }17 ]18 }19 ]20 }21}
Error response fields
Primary fields | |
---|---|
Field | Description |
| Detailed information about the error. |
detailedError object | |
Field | Description |
| One of the defined error codes. |
| A human-readable description of the error code. It is intended as an aid to developers and is not suitable for exposure to end users. |
| Optional. Target of the particular error. For example, a parameter name, a path to a JSON property, and others. Contents of this field may change over time. |
| Optional. An array of root causes (more detailed errors) that led to
this error. |
| Optional. A higher level of details about this error. |
innerError object | |
Field | Description |
| One of the defined error codes. |
| Optional. |
| Optional. A higher level of details about this error. |
Error code hierarchy
List of predefined, hierarchical, human-readable error codes.
- Top level codes relate to HTTP error codes.
- They may be refined by error codes in
details
orinnerError
. - Further levels of refinement are possible by nesting
innerError
insideinnerError
.
In the future, the list may be extended with additional codes. New or existing codes may be introduced as children of codes already present in the hierarchy. The application must be ready for the occurrence of an unknown error code (e.g., by stopping error processing at the last understood level of detail).
Each of the following error codes has a scope assigned. Scope assignment is subject to change and extension. Possible scopes are:
job
- the error code concerns the whole job.- It may be included in the optional
detailedError
structure.
- It may be included in the optional
cell
- the error code concerns failed processing of one of the matrix cells.- It may be included in the optional
data.detailedError
structure. - Codes in this scope, apart from the
CELL_PROCESSING_ERROR
code, may also be included in the optionalfailureDetails
array.
- It may be included in the optional
Error code | Description | Scope |
---|---|---|
NOT_FOUND | Top level code for requests which failed with an HTTP |
|
BAD_REQUEST | Top level code for requests which failed with an HTTP |
|
MATRIX_REQUEST_TIMEOUT | Top level code for requests which failed with an HTTP
|
|
TOO_MANY_MATRIX_REQUESTS | Top level code for requests which failed with an
HTTP |
|
INTERNAL_SERVER_ERROR | Top level code for requests which failed with an HTTP |
|
SERVICE_UNAVAILABLE | Top level code for requests which failed with an HTTP |
|
FORBIDDEN | Top level code for requests which failed with an HTTP |
|
BAD_ARGUMENT | One of the request parameters did not pass validation. The optional
|
|
OVER_TRANSACTION_LIMIT | Client has exceeded the transaction limit. |
|
MALFORMED_BODY | POST body is not properly formatted. |
|
ILLEGAL_PARAMETER | Unsupported request parameter was specified. |
|
MISSING_REQUIRED_PARAMETER | One of the required parameters was not provided. |
|
INVALID_PARAMETER_VALUE | The value of one of the parameters is invalid. |
|
CELL_PROCESSING_ERROR | This is the top level code for the
The NO_ROUTE_FOUND and MAP_MATCHING_FAILURE cell failures are charged like successful route calculations. |
|
UNKNOWN | Unknown error has occurred. |
|
MAP_MATCHING_FAILURE | One of the input points (origin, destination) could not be matched to the map because there is no known drivable section near this point. |
|
NO_ROUTE_FOUND | No valid route found for the given input parameters. |
|
CELL_TIMEOUT | Failed to calculate route summary for the given origin and destination pair before the sync request timeout passed. The CELL_TIMEOUTs may be caused by:
|
|
OUT_OF_REGION | The distance between the given origin and destination pair is too long to calculate the route, considering other requested options. See the API Limitations table for more information. |
|