Sorry, you need to enable JavaScript to visit this website.

Asynchronous Batch Submission

 

Service version: 1
Last edit: 2019.02.21

On this page

Purpose

The Asynchronous Batch Submission endpoint allows the submission of a new batch for asynchronous processing. It responds with a redirect to the location at which the batch results can be obtained when the batch processing has completed.

Request data

HTTPS Method: POST

URL format

For ease of viewing and identification:

  • Required constants and parameters are shown in bold text.
  • Optional parameters are shown in plain text.
https://baseURL/routing/versionNumber/batch/outputFormat?key=*****&redirectMode=redirectMode

Example

https://api.tomtom.com/routing/1/batch/json?key=*****

▲ Return to top

HTTP Request headers

The following data table describes HTTP Request headers of particular interest to Batch service clients.

Required headers
Header Description
Content-Type
string
Specifies the MIME type of the body of the Request. It may be:

  • application/xml
  • application/json
Optional headers
Header Description
Tracking-ID
string
Specifies an identifier for the Request.

  • It can be used to trace a call.
  • The value must match the regular expression '^[a-zA-Z0-9-]{1,100}$'.
  • An example of format that matches this regular expression is UUID (e.g., 9ac68072-c7a4-11e8-a8d5-f2801f1b9fd1). For details check RFC 4122.
  • If specified, it is replicated in the Tracking-ID Response header.

▲ Return to top

Request parameters

The following table describes the parameters that can be used in a Request.

  • Required parameters must be used or the call will fail.
  • Optional parameters may be used.
  • A parameter's data type is beneath its name.
Required parameters
Parameter Description
baseURL
string
Base URL for calling the API:
Value: api.tomtom.com
versionNumber
integer
Service version number.
Value: The current value is 1.
key
string
An API Key valid for the requested service.
Value: Your valid API Key.
Optional parameters
Parameter Description
outputFormat
string
The content type of the Response structure.
If it is not provided, then xml is assumed as default.
Value: It may be either:

  • json
  • xml
redirectMode
string
Controls the HTTP code of the successful HTTP Response to the Submission Request.
Value:

  • When set to auto, HTTP code 303 is returned. The HTTP client may automatically redirect to the download endpoint.
  • When set to manual, HTTP code 202 is returned. The HTTP client will not automatically redirect to the download endpoint.

In both cases the same Location header is included.

▲ Return to top

POST body (XML)

<?xml version="1.0" encoding="utf-8"?>
<batchRequest>
    <batchItems>
        <batchItem>
            <query>...</query>
        </batchItem>
        ...
        <batchItem>
            <query>...</query>
            <post>...</post>
        </batchItem>
    </batchItems>
</batchRequest>

POST body (JSON)

{
  "batchItems": [
    {"query": "..."},
    ...
    {
        "query": "...",
        "post": {...}
    }
  ]
}

POST body fields (XML)

Field Description
batchRequest Root element of the Request.
Value: The XML root element.
batchItems A set of batch items.
Value: The maximum number of batch items for an Asynchronous API is 700.
batchItem A single batch item.
Value: One batch item.
query A string used to build a Request to the Routing service.

  • It is a partial URL without protocol, base URL, service version or API key parts.
  • The output format (last path element) must match the outputFormat parameter of the batch Request.

Value: When posting XML to the Batch Routing service, the <query> element values must be valid XML (e.g., the & character must be replaced by the predefined XML entity &amp;). More information is available in the List of XML character entity references.

Please note that the callback parameter is not supported by Batch Routing. For detailed descriptions refer to the documentation of Calculate Route and Calculate Reachable Range services.

post Contains data that is passed to Calculate Route or Calculate Reachable Range services using the HTTP POST method.

  • The POST data format must match the Content-Type header of a submitted batch request i.e., it should be in JSON format when the Content-Type is set to application/json and should be in XML format if the Content-Type is set to application/xml.
  • Please refer to POST Data Parameters section of Calculate Route and Calculate Reachable Range services documentation for detailed descriptions and examples of XML and JSON content for this field.

▲ Return to top

POST body examples

Each batch Request can contain items corresponding to multiple API endpoints of the Routing API suite.

  • For each API, the same body structure applies, and the specific parameters of each endpoint are expected to go into query elements.
  • An example of mixed Routing API suite query items inside of the batch Request body structures can be found below.
  • For details on the particular API usage, consult the respective API documentation pages.

XML POST body format example

<?xml version="1.0" encoding="utf-8"?>
<batchRequest>
  <batchItems>
    <batchItem>
      <query>/calculateRoute/52.36006039665441,4.851064682006836:52.36187528311709,4.850560426712036/xml?travelMode=car&amp;routeType=shortest&amp;traffic=true&amp;departAt=now&amp;maxAlternatives=0</query>
    </batchItem>
    <batchItem>
      <query>/calculateRoute/52.36241907934766,4.850034713745116:52.36173769505809,4.852169752120972/xml?travelMode=teleport&amp;routeType=shortest&amp;traffic=true&amp;departAt=now</query>
    </batchItem>
    <batchItem>
      <query>/calculateRoute/52.23292,21.06179:43.29379,17.01963/xml</query>
      <post>
        <postData>
          <avoidVignette>
            AUS,CHE
          </avoidVignette>
        </postData>
      </post>
    </batchItem>
    <batchItem>
      <query>/calculateReachableRange/52.36187528311709,4.850560426712036/xml?fuelBudgetInLiters=20&amp;constantSpeedConsumptionInLitersPerHundredkm=50,6</query>
    </batchItem>
    <batchItem>
      <query>/calculateReachableRange/52.36173769505809,4.852169752120972/xml?timeBudgetInSec=1800</query>
    </batchItem>
  </batchItems>
</batchRequest>

▲ Return to top

JSON POST body format example

{
  "batchItems": [
    {"query": "/calculateRoute/52.36006039665441,4.851064682006836:52.36187528311709,4.850560426712036/json?travelMode=car&routeType=shortest&traffic=true&departAt=now&maxAlternatives=0"},
    {"query": "/calculateRoute/52.36241907934766,4.850034713745116:52.36173769505809,4.852169752120972/json?travelMode=teleport&routeType=shortest&traffic=true&departAt=now"},
    {
      "query": "/calculateRoute/52.23292,21.06179:43.29379,17.01963/json",
      "post": {
        "avoidVignette": [
          "AUS",
          "CHE"
        ]
      }
    },
    {"query": "/calculateReachableRange/52.36187528311709,4.850560426712036/json?fuelBudgetInLiters=20&constantSpeedConsumptionInLitersPerHundredkm=50,6"},
    {"query": "/calculateReachableRange/52.36173769505809,4.852169752120972/json?timeBudgetInSec=1800"}
  ]
}

▲ Return to top

Response data

Batch Submission Response

On a successful Batch Request submission, the Batch Routing service responds with a HTTP 303 redirect to the Batch Download endpoint. The response has a Location header with a link to that endpoint and no body. In case of an error, a body is present.

HTTP Status codes

Code Meaning and Possible Causes
202 Accepted:

  • A HTTP Response with a Location header that points where the batch results can be obtained.
  • This code is used when redirectMode is set to manual.
303 See Other:

  • A HTTP Response with Location header that points where the batch results can be obtained.
  • This code is used when redirectMode is set to auto.
400 Bad Request:

  • Missing required parameters.
  • Exceeded maximum number of batch items.
  • Parameters did not pass validation.
403 Forbidden:

  • The API Key is missing, inactive, invalid, not entitled to use Batch Routing API over QPS or over QPD.
  • Can also occur when using HTTP instead of HTTPS.
404 Not Found: The requested resource could not be found, but it may be available again in the future.
405 Method Not Allowed: The client used an HTTP method other than POST.
408 Request timeout: The Request sent to the server took longer than it was prepared to wait.
414 Requested URI is too long: Indicates that the URI requested by the client is longer than the server is willing to interpret.
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.

▲ Return to top

HTTP Response headers

The following table describes HTTP Response headers of particular interest to Batch service clients.

Header Description
Access-Control-Expose-Headers A comma separated list of HTTP header names that browsers are allowed to access.
Value: Content-Length
Access-Control-Allow-Origin A header instructing browsers to allow customer websites to contact the Batch Routing service.
Value: *
Content-Encoding The Batch Routing service applies gzip compression to the Responses if it is requested by the client with the Accept-Encoding header.
Value: gzip
Content-Type The format of the Response as chosen by the client (see the contentType Request parameter).
Value: application/json; charset=utf-8
Location Indicates the location where the batch results can be downloaded.
Value: URI
Tracking-ID An identifier for the Request.

  • If the Tracking-ID header was specified, it is replicated in the response.
  • Otherwise, it is generated automatically by the service.

Value: Tracking-ID

Error Response example

The error Response content type depends on the outputFormat parameter.

XML error example:

<?xml version="1.0" encoding="utf-8"?>
  <batchResponse xmlns="http://api.tomtom.com/batch" formatVersion="0.0.1">
    <error description="Output format: csv is unsupported."/>
  </batchResponse>

JSON example:

{
  "formatVersion": "0.0.1",
  "error": {
    "description": "Output format: csv is unsupported."
  }
}

Error Response fields

Field Description
batchResponse Root element of the batch error Response.
formatVersion Version of batch error Response format.
error Element describing the error.
description Error description string.

▲ Return to top

You are here