Source: https://developers.woosmap.com/api-reference/distance-api/post-distance-distancematrix-json/

> For clean Markdown of any page, append `.md` to the page URL.

> Routing index (which page answers which question): https://developers.woosmap.com/llms.txt

> Full page list: https://developers.woosmap.com/llms-full.txt

# Calculate Matrix



POST 
https://api.woosmap.com/distance/distancematrix/json

Get distances and durations for a matrix of origins and destinations, based on the recommended route between start and end points for a specified travel mode.

Traffic calculations use the optional `departure_time` parameter. Matrix requests reject any non-null `arrival_time` value with HTTP 200 and `INVALID_REQUEST`. Omitting `arrival_time`, or setting it to JSON `null` in a POST body, is accepted.

**Rate limit** : `20 requests/2s` GET and POST

**Elements limit** : `1000 elements/1s` GET and POST

**Rate limit with TRAFFIC** : `20 requests/2s` GET and POST

**Elements limit with TRAFFIC** : `1000 elements/1s` GET and POST

### Authorization

[`key`](#authorization-distance-publicapikey)

_apiKey · query_

Public key of the project (starts with `woos-`) or an API key (a UUID).

[`private_key`](#authorization-distance-privateapikey)

_apiKey · query_

Private key with or without write permission.

[`X-Api-Key`](#authorization-distance-privateapikeyheader)

_apiKey · header_

Private key with or without write permission.

### Header Parameters

[`accept-language`](#header-accept-language)

_string_

### Request Body

application/json

[`origins`](#req-origins)

_string · required_

The starting points. You can supply one or more locations, in the form of `latitude,longitude` coordinates, separated by the pipe character `|`. Ensure that no space exists between the latitude and longitude values.

In order to reduce URL size, [encoded polylines](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) are also supported using `enc:<encoded-polyline>:`

[`destinations`](#req-destinations)

_string · required_

The ending points. You can supply one or more locations, in the form of `latitude,longitude` coordinates, separated by the pipe character `|`. Ensure that no space exists between the latitude and longitude values.

In order to reduce URL size, [encoded polylines](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) are also supported using `enc:<encoded-polyline>:`

[`mode`](#req-mode)

_string · Defaults to driving_

Specifies the mode of transport to use for the calculation.

Available options: `driving`, `walking`, `cycling`

[`method`](#req-method)

_string · Defaults to time_

Specifies how to compute the route between the start point and the end point:

- `time`: fastest route 
- `distance`: shortest route

Available options: `time`, `distance`

[`units`](#req-units)

_string · Defaults to metric_

Specifies the unit system to use when displaying results.

Available options: `metric`, `imperial`

[`language`](#req-language)

_string · Defaults to en_

The language code, indicating in the language the response should be in.

If not defined the header `Accept-Language` of the request will be checked before defaulting to `en`.

**28 enum values**

`en`

`fr`

`bg`

`ca`

`cs`

`da`

`de`

`el`

`es`

`et`

`fi`

`he`

`hi`

`hu`

`it`

`ja`

`nb`

`nl`

`pl`

`pt`

`ro`

`ru`

`sk`

`sl`

`sv`

`tr`

`uk`

`zh`

[`avoid`](#req-avoid)

_string | null_

A list of features that you want to avoid. Valid values are `tolls`, `highways`, `ferries` or polygons coordinates whose vertex latlng are separated by a semicolon `;`.

To add multiple features, separate them with the pipe `|` character.

[`departure_time`](#req-departure-time)

_string | null_

Specify your desired departure time.

By using this parameter, Distance will calculate the duration with **traffic**. Valid values are a UNIX timestamp (e.g. `1600799173` for the date: `22/09/2020 20:26:13`) or `now`.

[`elements`](#req-elements)

_string · Defaults to distance_

Specifies element values that will be part of the API response (`distance` and/or `duration`).

Available options: `distance`, `duration`, `duration_distance`

##### Example

```json
{
  "origins": "48.73534,2.368308|48.73534,2.368308",
  "destinations": "48.83534,2.368308",
  "units": "imperial",
  "elements": "duration_distance",
  "method": "distance",
  "departure_time": "now"
}
```

### Response

200application/json

Successful Response

[`status`](#resp-200-status)

_string · Defaults to OK_

The status of the response

- `OK`: The response contains a valid result.
- `INVALID_REQUEST`: The request could not be processed.
- `MAX_ELEMENTS_EXCEEDED`: The product of origins and destinations exceeds the per-query limit (fixed at 200 elts/query). Driving matrices with `departure_time` are also limited to 15 origins and 100 destinations. This origin limit increases to 100 when there is only one destination.
- `MAX_ROUTE_LENGTH_EXCEEDED`: One of the requested routes is too long and the matrix/route cannot be processed (The limit is 1000km for routes and 1000km for matrices when driving, 250km and 200km when walking, 500km and 500km when cycling). Routes add up the straight-line distances between consecutive locations, including waypoints. With `optimize:true` and two or more waypoints on a Route without traffic, each pair of locations uses the matrix limit instead.
- `REQUEST_DENIED`: The API key provided is invalid or does not allow access to this service etc..
- `BACKEND_ERROR`: The server encountered an unexpected error.
- `BACKEND_UNAVAILABLE`: The service is temporarily unavailable or the request timed out.
- `OVER_QUERY_LIMIT`: The request was denied due to the rate limit (see [Usage Limits](https://developers.woosmap.com/products/distance-api/distance-matrix-endpoint/#usage-limits)).
- `ZERO_RESULTS`: No route could be found between the origin and destination.

**9 enum values**

`OK`

`INVALID_REQUEST`

`MAX_ELEMENTS_EXCEEDED`

`MAX_ROUTE_LENGTH_EXCEEDED`

`REQUEST_DENIED`

`BACKEND_ERROR`

`BACKEND_UNAVAILABLE`

`OVER_QUERY_LIMIT`

`ZERO_RESULTS`

[`rows`](#resp-200-rows)

_object[] · required_

Contains an array of elements for each pair of origin and destination

**1 properties**

rows.[`elements`](#resp-200-rows-elements)

_object[] · required_

An array of each route element.

### Errors

#401

Unable to locate credentials.

 

`application/json`

[`detail`](#err-401-detail)

_string · required_

#402

Out of free quota.

 

`application/json`

[`detail`](#err-402-detail)

_string · required_

#403

Credentials found, but not matching.

 

`application/json`

[`detail`](#err-403-detail)

_string · required_

#422

Validation Error

 

`application/json`

[`detail`](#err-422-detail)

_object[]_

**5 properties**

detail.[`loc`](#err-422-detail-loc)

_any[] · required_

detail.[`msg`](#err-422-detail-msg)

_string · required_

detail.[`type`](#err-422-detail-type)

_string · required_

detail.[`input`](#err-422-detail-input)

_any_

detail.[`ctx`](#err-422-detail-ctx)

_object_

#429

Rate limit reached

 

`application/json`

[`detail`](#err-429-detail)

_string · required_

```shell
curl -L 'https://api.woosmap.com/distance/distancematrix/json?private_key=YOUR_PRIVATE_API_KEY' \
-H 'content-type: application/json' \
-d '{
  "origins": "48.73534,2.368308|48.73534,2.368308",
  "destinations": "48.83534,2.368308",
  "units": "imperial",
  "elements": "duration_distance",
  "method": "distance",
  "departure_time": "now"
}'
```

```javascript
const myHeaders = new Headers();
myHeaders.append("content-type", "application/json");

const raw = JSON.stringify({
  "origins": "48.73534,2.368308|48.73534,2.368308",
  "destinations": "48.83534,2.368308",
  "units": "imperial",
  "elements": "duration_distance",
  "method": "distance",
  "departure_time": "now"
});

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow"
};

fetch("https://api.woosmap.com/distance/distancematrix/json?private_key=YOUR_PRIVATE_API_KEY", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

```python
import requests
import json

url = "https://api.woosmap.com/distance/distancematrix/json?private_key=YOUR_PRIVATE_API_KEY"

payload = json.dumps({
    "origins": "48.73534,2.368308|48.73534,2.368308",
    "destinations": "48.83534,2.368308",
    "units": "imperial",
    "elements": "duration_distance",
    "method": "distance",
    "departure_time": "now"
})
headers = {
    'content-type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

```json
{
  "status": "OK",
  "rows": [
    {
      "elements": [
        {
          "status": "OK",
          "duration": {
            "value": 2406,
            "text": "40 mins"
          },
          "distance": {
            "value": 12210,
            "text": "7.6 miles"
          }
        }
      ]
    },
    {
      "elements": [
        {
          "status": "OK",
          "duration": {
            "value": 2406,
            "text": "40 mins"
          },
          "distance": {
            "value": 12210,
            "text": "7.6 miles"
          }
        }
      ]
    }
  ]
}
```
