Skip to main content
The Distance API calculates the routes and distances of a transport chain – by road, rail, water, and air – without calculating emissions. It returns the distance of each operation and of the whole chain, the locations TerraTwin resolved, including the airports, harbors, and rail yards it chose, and optionally each route as a polyline. New to the Distance API? Start with the Distance API quick start.

Endpoint

The endpoint is served from https://api.terratwin.com/api/v1/transportation and needs your API key in the x-api-key header.

Same routing as the Emissions API

A Distance API request is routed exactly as the Emissions API routes the same request: the same location matching, transport modes, fallback modes, airports, stopovers, harbors, ferries, and rail yards. So the routes and distances it returns are the ones an emissions calculation of that shipment is based on.
The Distance API returns the routed distances as they are. The Emissions API applies distance adjustment factors to some modes when calculating emissions, so the distance used in an emissions calculation can be slightly longer than the Distance API’s.

The request

The request has the same structure as an emissions request: Each transport operation is one of ROAD, RAIL, WATER, AIR, or UNKNOWN. Operation properties that affect the route – such as the vessel and navigation constraints of a WATER leg, or the aircraft of an AIR leg – work as described in each mode’s guide. Compared with the Emissions API, a Distance API request doesn’t take:
  • WEIGHTED_MODES operations
  • firstMile and lastMile on AIR, RAIL, and WATER operations – connecting road journeys are still routed and included in the distances
  • hubType on a HUB – a hub only needs a type and a location, and marks where one leg ends and the next begins
  • The emissions-only options storeResult, hubInsertion, and defaultHubTypes

Options

The response

Each leg in transportChain has:
  • type – the mode of the leg. For an UNKNOWN operation, it’s the fallback mode that was used.
  • start and end – the resolved locations where the leg begins and ends.
  • distanceKm – the distance of the leg, including its connecting road journeys.
  • elements – the operations that make up the leg, in order. A WATER leg from an address, for example, is a ROAD journey to the departure harbor followed by the WATER voyage. AIR elements show the aircraft, and WATER elements the vessel and its capacity band.
  • subOperations on a ROAD element – roll-on/roll-off ferry (WATER) and train (RAIL) crossings, such as the Channel Tunnel shuttle.
Results aren’t stored, so there is no endpoint to retrieve them later.

Credits

Distance API requests are charged to your account’s Distance API credits, counted in the same way as for the Emissions API – one credit per transport operation – see Credits & usage. If your account has no Distance API credits left, requests are rejected with 403 and error code 42, “Your account has no remaining route credits”. Emissions API credits are never used for Distance API requests.

Emissions API

Need the emissions of the journey as well? The Emissions API takes the same transport chain and calculates its emissions.

API reference

Every request field, response object, and error code of the Distance API.