Route - Post Route Directions Batch Preview

Route Directions Batch API

Applies to: S1 pricing tier.

The Route Directions Batch API allows the caller to batch up to 700 Route Directions API queries/requests using just a single API call.

Submit Batch Request

To send the route directions queries you will use a POST request where the request body will contain the batchItems array in json format and the Content-Type header will be set to application/json. Here's a sample request body containing 3 route directions queries:

{
    "batchItems": [
        { "query": "?query=47.620659,-122.348934:47.610101,-122.342015&travelMode=bicycle&routeType=eco&traffic=false" },
        { "query": "?query=40.759856,-73.985108:40.771136,-73.973506&travelMode=pedestrian&routeType=shortest" },
        { "query": "?query=48.923159,-122.557362:32.621279,-116.840362" }
    ]
}

A route directions query in a batch is just a partial URL without the protocol, base URL, path, api-version and subscription-key. It can accept any of the supported route directions URI parameters. The string values in the route directions query must be properly escaped (e.g. " character should be escaped with \ ) and it should also be properly URL-encoded.

The maximum number of queries that can be specified in the batch is 700 and the batch should contain at least 1 query.

Please note that the Route Directions Batch API is a long-running request. Here's a typical sequence of operations:

  1. Client sends a Route Directions Batch POST request to Azure Maps

  2. The server will respond with one of the following:

    HTTP 202 Accepted - Batch request has been accepted.

    HTTP Error - There was an error processing your Batch request. This could either be a 400 Bad Request or any other Error status code.

  3. If the batch request was accepted successfully, the Location header in the response contains the URL to download the results of the batch request.

  4. Client issues a GET request on the download URL obtained in Step 3 to download the batch results.

Download Batch Results

To download the batch results you will issue a GET request to the batch download endpoint. This download URL can be obtained from the Location header of a successful POST batch request and looks like the following:

https://atlas.microsoft.com/batch/{batch-id}?api-version=1.0&subscription-key={subscription-key}

Here's the typical sequence of operations for downloading the batch results:

  1. Client sends a GET request using the download URL.

  2. The server will respond with one of the following:

    HTTP 202 Accepted - Batch request was accepted but is still being processed. Please try again in some time.

    HTTP 200 OK - Batch request successfully processed. The response body contains all the batch results.

Batch Response Model

When downloading the results of a batch request, if the batch has finished processing, the response body contains the batch response. This batch response contains a summary component that indicates the totalRequests that were part of the original batch request and successfulRequestsi.e. queries which were executed successfully. The batch response also includes a batchItems array which contains a response for each and every query in the batch request. Also, the batchItems will contain the results in the exact same order the original queries were sent in the batch request. Each item in batchItems contains statusCode and response fields. Each response in batchItems is of one of the following types:

  • RouteDirectionsResponse - If the query completed successfully.

  • Error - If the query failed. The response will contain a code and a message in this case.

Here's a sample Batch Response with 1 successful and 1 failed result:

{
    "summary": {
        "successfulRequests": 1,
        "totalRequests": 2
    },
    "batchItems": [
        {
            "statusCode": 200,
            "response": {
                "routes": [
                    {
                        "summary": {
                            "lengthInMeters": 1758,
                            "travelTimeInSeconds": 387,
                            "trafficDelayInSeconds": 0,
                            "departureTime": "2018-07-17T00:49:56+00:00",
                            "arrivalTime": "2018-07-17T00:56:22+00:00"
                        },
                        "legs": [
                            {
                                "summary": {
                                    "lengthInMeters": 1758,
                                    "travelTimeInSeconds": 387,
                                    "trafficDelayInSeconds": 0,
                                    "departureTime": "2018-07-17T00:49:56+00:00",
                                    "arrivalTime": "2018-07-17T00:56:22+00:00"
                                },
                                "points": [
                                    {
                                        "latitude": 47.62094,
                                        "longitude": -122.34892
                                    },
                                    {
                                        "latitude": 47.62094,
                                        "longitude": -122.3485
                                    },
                                    {
                                        "latitude": 47.62095,
                                        "longitude": -122.3476
                                    }
                                ]
                            }
                        ],
                        "sections": [
                            {
                                "startPointIndex": 0,
                                "endPointIndex": 40,
                                "sectionType": "TRAVEL_MODE",
                                "travelMode": "bicycle"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "statusCode": 400,
            "response":
            {
                "error":
                {
                    "code": "400 BadRequest",
                    "message": "Bad request: one or more parameters were incorrectly specified or are mutually exclusive."
                }
            }
        }
    ]
}

Data Retention Period

Please, be aware that batch results are available for download for 14 days, after which the request for results download will return 404 Not Found response.

POST https://atlas.microsoft.com/route/directions/batch/json?api-version=1.0
POST https://atlas.microsoft.com/route/directions/batch/json?subscription-key={subscription-key}&api-version=1.0

URI Parameters

Name In Required Type Description
format
path True

Desired format of the response. Only json format is supported.

subscription-key
query
  • string

One of the Azure Maps keys provided from an Azure Map Account. Refer to the subscription-key security definition.

api-version
query True
  • string

Version number of Azure Maps API. Current version is 1.0

Request Header

Name Required Type Description
x-ms-client-id
  • string

Specifies which account is intended for usage in conjunction with the Azure AD security model. It represents a unique ID for the Azure Maps account and can be retrieved from Azure Maps management plane Account API. To use Azure AD security in Azure Maps see the following articles for guidance.

Request Body

Name Type Description
batchItems

The list of queries/requests to process

Responses

Name Type Description
200 OK

OK

202 Accepted
  • object

Request Accepted: The request has been accepted for processing. Please use the URL in the Location Header to retry or access the results.

Headers

  • Location: string
400 Bad Request

Bad request: one or more parameters were incorrectly specified or are mutually exclusive.

401 Unauthorized

Access denied due to invalid subscription key or invalid Azure Active Directory bearer token. Make sure to provide a valid key for an active Azure subscription and Maps resource. Otherwise, verify the WWW-Authenticate header for error code and description of the provided AAD bearer token.

Headers

  • WWW-Authenticate: string
403 Forbidden

Permission, capacity, or authentication issues.

404 Not Found

Not Found: the requested resource could not be found, but it may be available again in the future.

500 Internal Server Error

An error occurred while processing the request. Please try again later.

Security

azure_auth

These are the Azure Active Directory OAuth2 Flows. When paired with Azure Role Based Access control it can be used to control access to Azure Maps REST APIs. Azure Role based access controls are used to designate access to one or more Azure Maps resource account or sub-resources. Any user, group, or service principal can be granted access via a built in role or a custom role composed of one or more permissions to Azure Maps REST APIs.

To implement scenarios we recommend viewing authentication concepts. In summary, this security definition provides a solution for modeling application(s) via objects capable of access control on specific APIs and scopes.

Note

  • This security definition requires the use of the x-ms-client-id header to indicate which Azure Maps resource the application is requesting access to. This can be acquired from the Maps management API.
  • The Authorization URL is specific to the Azure public cloud instance. Sovereign clouds have unique Authorization URLs and Azure Active directory configurations.
  • The Azure role based access control is configured from the Azure management plane via Azure portal, Powershell, CLI, Azure SDKs, or REST APIs.
  • Usage of the Azure Maps Web SDK allows for configuration based setup of an application for multiple use cases.
  • Currently Azure Active Directory v1.0 tokens are supported.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

subscription-key

This is a shared key which is provisioned when creating an Azure Maps resource through the Azure management plane via Azure portal, Powershell, CLI, Azure SDKs, or REST APIs. With this key, any application is authorized to access all REST APIs. In other words, these can currently be treated as master keys to the account which they are issued for. For publicly exposed applications our recommendation is to use server to server access of Azure Maps REST APIs where this key can be securely stored.

Type: apiKey
In: query

Examples

A Route Directions Batch API call containing 3 Route Directions API queries

Sample Request

POST https://atlas.microsoft.com/route/directions/batch/json?subscription-key=[subscription-key]&api-version=1.0
{
  "batchItems": [
    {
      "query": "?query=47.639987,-122.128384:47.621252,-122.184408:47.596437,-122.332000&routeType=fastest&travelMode=car&maxAlternatives=99"
    },
    {
      "query": "?query=47.620659,-122.348934:47.610101,-122.342015&travelMode=bicycle&routeType=eco&traffic=false"
    },
    {
      "query": "?query=40.759856,-73.985108:40.771136,-73.973506&travelMode=pedestrian&routeType=shortest"
    }
  ]
}

Sample Response

{
  "batchItems": [
    {
      "statusCode": 400,
      "response": {
        "error": {
          "code": "400 BadRequest",
          "message": "maxAlternatives parameter value should be between 0 and 5 inclusive"
        }
      }
    },
    {
      "statusCode": 200,
      "response": {
        "formatVersion": "0.0.12",
        "copyright": "Copyright 2019 TomTom International BV. All rights reserved. This navigation data is the proprietary copyright of TomTom International BV and may be used only in accordance with the terms of a fully executed license agreement entered into between TomTom International BV, or an authorised reseller and yourself. If you have not entered into such a license agreement you are not authorised to use this data in any manner and should immediately return it to TomTom International BV.",
        "privacy": "TomTom keeps information that tells us how and when you use our services. This includes information about the device you are using and the information we receive while you use the service, such as locations, routes, destinations and search queries. TomTom is unable to identify you based on the information it collects, and will not try to. TomTom uses the information for technical diagnostics, to detect fraud and abuse, to create usage reports, and to improve its services. The information is kept only for these purposes and for a limited period of time, after which it is destroyed. TomTom applies security methods based on industry standards to protect the information against unauthorised access. TomTom will not give anyone else access to the information or use it for any other purpose, unless explicitly and lawfully ordered to do so following due legal process. You can find out more at http://tomtom.com/privacy. You can contact TomTom by going to http://tomtom.com/support.",
        "routes": [
          {
            "summary": {
              "lengthInMeters": 1754,
              "travelTimeInSeconds": 386,
              "trafficDelayInSeconds": 0,
              "departureTime": "2019-06-21T22:56:23+00:00",
              "arrivalTime": "2019-06-21T23:02:49+00:00"
            },
            "legs": [
              {
                "summary": {
                  "lengthInMeters": 1754,
                  "travelTimeInSeconds": 386,
                  "trafficDelayInSeconds": 0,
                  "departureTime": "2019-06-21T22:56:23+00:00",
                  "arrivalTime": "2019-06-21T23:02:49+00:00"
                },
                "points": [
                  {
                    "latitude": 47.62094,
                    "longitude": -122.34892
                  },
                  {
                    "latitude": 47.62094,
                    "longitude": -122.3485
                  },
                  {
                    "latitude": 47.62095,
                    "longitude": -122.3476
                  },
                  {
                    "latitude": 47.60995,
                    "longitude": -122.34174
                  },
                  {
                    "latitude": 47.61011,
                    "longitude": -122.342
                  }
                ]
              }
            ],
            "sections": [
              {
                "startPointIndex": 0,
                "endPointIndex": 44,
                "sectionType": "TRAVEL_MODE",
                "travelMode": "bicycle"
              }
            ]
          }
        ]
      }
    },
    {
      "statusCode": 200,
      "response": {
        "formatVersion": "0.0.12",
        "copyright": "Copyright 2019 TomTom International BV. All rights reserved. This navigation data is the proprietary copyright of TomTom International BV and may be used only in accordance with the terms of a fully executed license agreement entered into between TomTom International BV, or an authorised reseller and yourself. If you have not entered into such a license agreement you are not authorised to use this data in any manner and should immediately return it to TomTom International BV.",
        "privacy": "TomTom keeps information that tells us how and when you use our services. This includes information about the device you are using and the information we receive while you use the service, such as locations, routes, destinations and search queries. TomTom is unable to identify you based on the information it collects, and will not try to. TomTom uses the information for technical diagnostics, to detect fraud and abuse, to create usage reports, and to improve its services. The information is kept only for these purposes and for a limited period of time, after which it is destroyed. TomTom applies security methods based on industry standards to protect the information against unauthorised access. TomTom will not give anyone else access to the information or use it for any other purpose, unless explicitly and lawfully ordered to do so following due legal process. You can find out more at http://tomtom.com/privacy. You can contact TomTom by going to http://tomtom.com/support.",
        "routes": [
          {
            "summary": {
              "lengthInMeters": 1772,
              "travelTimeInSeconds": 1276,
              "trafficDelayInSeconds": 0,
              "departureTime": "2019-06-21T22:56:23+00:00",
              "arrivalTime": "2019-06-21T23:17:38+00:00"
            },
            "legs": [
              {
                "summary": {
                  "lengthInMeters": 1772,
                  "travelTimeInSeconds": 1276,
                  "trafficDelayInSeconds": 0,
                  "departureTime": "2019-06-21T22:56:23+00:00",
                  "arrivalTime": "2019-06-21T23:17:38+00:00"
                },
                "points": [
                  {
                    "latitude": 40.75982,
                    "longitude": -73.98493
                  },
                  {
                    "latitude": 40.7601,
                    "longitude": -73.98483
                  },
                  {
                    "latitude": 40.75984,
                    "longitude": -73.98417
                  },
                  {
                    "latitude": 40.76047,
                    "longitude": -73.9837
                  },
                  {
                    "latitude": 40.77095,
                    "longitude": -73.9736
                  },
                  {
                    "latitude": 40.77114,
                    "longitude": -73.97356
                  }
                ]
              }
            ],
            "sections": [
              {
                "startPointIndex": 0,
                "endPointIndex": 47,
                "sectionType": "TRAVEL_MODE",
                "travelMode": "pedestrian"
              }
            ]
          }
        ]
      }
    }
  ],
  "summary": {
    "successfulRequests": 2,
    "totalRequests": 3
  }
}
Location: URL to download the results of the long-running batch request.
{}
{
  "error": {
    "code": "400 BadRequest",
    "message": "Bad request: one or more parameters were incorrectly specified or are mutually exclusive."
  }
}
{
  "error": {
    "code": "401 Unauthorized",
    "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."
  }
}
{
  "error": {
    "code": "403 Forbidden",
    "message": "Permission, capacity, or authentication issues."
  }
}
{
  "error": {
    "code": "404 NotFound",
    "message": "Not Found: the requested resource could not be found, but it may be available again in the future."
  }
}
{
  "error": {
    "code": "500 InternalServerError",
    "message": "An error occurred while processing the request. Please try again later."
  }
}

Definitions

BatchItems

The list of queries/requests to process

BatchRequestBody

This type represents the request body for the Batch service.

BatchResponse

This object is returned from a successful Batch service call

Error

This object is returned when an error occurs in the Maps API

ErrorResponse

This response object is returned when an error occurs in the Maps API

JsonFormat

Desired format of the response. Only json format is supported.

Summary

Summary for the batch request

BatchItems

The list of queries/requests to process

Name Type Description
query
  • string

Partial query string

BatchRequestBody

This type represents the request body for the Batch service.

Name Type Description
batchItems

The list of queries/requests to process

BatchResponse

This object is returned from a successful Batch service call

Name Type Description
batchItems
  • object[]

Array containing the batch results

summary

Summary for the batch request

Error

This object is returned when an error occurs in the Maps API

Name Type Description
code
  • string

The HTTP status code.

message
  • string

If available, a human readable description of the error.

ErrorResponse

This response object is returned when an error occurs in the Maps API

Name Type Description
error

This object is returned when an error occurs in the Maps API

JsonFormat

Desired format of the response. Only json format is supported.

Name Type Description
json
  • string

The JavaScript Object Notation Data Interchange Format

Summary

Summary for the batch request

Name Type Description
successfulRequests
  • integer

Number of successful requests in the batch

totalRequests
  • integer

Total number of requests in the batch