Skip to content

Detour Batch Mode

The endpoints in this section are used to create or remove larger sets of Detour segments. This can be useful for various use cases, for example:

  • an automated import of segments from another data source.
  • the transfer of many segments from one detour file into another one

See Python Detour Batch Example for an example.

Adding multiple Segments using Batch Mode

In certain scenarios like copying the contents of a Detour file to another one or importing from an external data source you have to add multiple segments at once. This has two advantages over adding the individual segments with one call each:

  • the performance is significantly higher
  • the import is treated as one transaction

The latter means that either all segments are imported successfully or, in case of an error, no segments are imported. In this case you will receive the response code 400 (Bad Request) with a reference to the first faulty segment.

The endpoint [POST] /detour/file/{fileid}/segments is very similar to [POST] /detour/file/{fileid}/segment. It expects an array of segments as parameter:

[
    {
        "coordinates": [
            {
                "lat": 50.701594,
                "lon": 7.140609
            },
            {
                "lat": 50.701862,
                "lon": 7.141112
            },
            {
                "lat": 50.701873,
                "lon": 7.141256
            },
            {
                "lat": 50.701896,
                "lon": 7.141328
            },
            {
                "lat": 50.702323,
                "lon": 7.142172
            }
        ],
        "openlr": "CwUT6SQN8j/kAgCcAEk/FQ==",
        "attributes": [
            {
                "name": "mod_restriction",
                "value": "block"
            }
        ]
    },
    {
        "coordinates": [
            {
                "lat": 50.736356,
                "lon": 7.091912
            },
            {
                "lat": 50.736925,
                "lon": 7.092388
            },
            {
                "lat": 50.736999,
                "lon": 7.092469
            },
            {
                "lat": 50.737067,
                "lon": 7.092567
            },
            {
                "lat": 50.737243,
                "lon": 7.092882
            }
        ],
        "openlr": "CwULCyQURjviAgBhAFk7FA==",
        "attributes": [
            {
                "name": "mod_restriction",
                "value": "block"
            }
        ]
    }
]

curl -X "POST" "https://api.maptrip.de/v1/detour/file/1234/segments?provider=TomTom" -H "accept: */*" -H "Authorization: Bearer <token>" -H "Content-Type: application/json" -d "[{\"coordinates\":[{\"lat\":50.701594,\"lon\":7.140609},{\"lat\":50.701862,\"lon\":7.141112},{\"lat\":50.701873,\"lon\":7.141256},{\"lat\":50.701896,\"lon\":7.141328},{\"lat\":50.702323,\"lon\":7.142172}],\"openlr\":\"CwUT6SQN8j/kAgCcAEk/FQ==\",\"attributes\":[{\"name\":\"mod_restriction\",\"value\":\"block\"}]},{\"coordinates\":[{\"lat\":50.736356,\"lon\":7.091912},{\"lat\":50.736925,\"lon\":7.092388},{\"lat\":50.736999,\"lon\":7.092469},{\"lat\":50.737067,\"lon\":7.092567},{\"lat\":50.737243,\"lon\":7.092882}],\"openlr\":\"CwULCyQURjviAgBhAFk7FA==\",\"attributes\":[{\"name\":\"mod_restriction\",\"value\":\"block\"}]}]"

Deleting all Detour Segments in a File

You can also delete all segments of a Detour file at once. This can be useful in combination with batch inserting of segments, for example, if you want to import segments automatically on a regular basis (see Python Detour Batch Example).

The endpoint [DELETE] /detour/file/{fileid}/segments deletes all segments in the specified file:

curl -X DELETE "https://api.maptrip.de/v1/detour/file/1234/segments?provider=TomTom" -H "accept: */*" -H "Authorization: Bearer <token>"

Important

This endpoint can only be used to delete segments. To delete newly created roads via Detour, see Delete a Road.