> ## Documentation Index
> Fetch the complete documentation index at: https://docs.terratwin.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Emissions API quick start

> Build your first Emissions API request step by step, then extend it to more detailed and multimodal transport chains.

The [Emissions API](https://docs.terratwin.com/content/guides/emissions-api.md) calculates the greenhouse gas emissions of moving cargo along a transport chain.
This tutorial builds a complete emissions request one part at a time.
By the end, you will have calculated the emissions for moving one metric tonne of cargo from Berlin to London by road.

![](https://mintcdn.com/terratwin/0hbUXmLqgbSI5-VO/images/quick-start/berlin-to-london-light.png?fit=max\&auto=format\&n=0hbUXmLqgbSI5-VO\&q=85\&s=b3ab5d2343c060e130fbad1bf647f49f)

Road transport from the Reichstag Building in Berlin to the Palace of Westminster in London

> [card] 1. Describe the cargo
>
> Define what is being moved and how much it weighs.

> [card] 2. Set the locations
>
> Define where the shipment starts and finishes.

> [card] 3. Build the chain
>
> Describe the ordered journey between those locations.

> [card] 4. Choose the operation
>
> Select how the cargo moves on each leg of the journey.

> [!NOTE]
>
> This first calculation deliberately relies on TerraTwin defaults for the road vehicle, loading, empty running, energy type, and other modelling inputs.
> Once the request works, use the linked guides to replace those defaults with information you know.

## Before you begin

You need:

* A TerraTwin account
* An API key from **[Manage API Keys](https://www.terratwin.com/account/settings/api-key-manager)**
* At least one Emissions API credit
* A way to send an HTTP request; this tutorial uses `curl` for the final test

If you haven't used TerraTwin before, start with the [Quick start](https://docs.terratwin.com/content/get-started/quick-start.md), which covers what all TerraTwin APIs have in common.

> [card] Authentication
>
> Every request must include your API key in the `x-api-key` header.
>
> See [API keys](https://docs.terratwin.com/content/guides/authentication.md) for creating, storing, rotating, and revoking keys.

> [card] Credits
>
> Calculations consume Emissions API credits according to the transport operations that TerraTwin processes.
>
> See [Credits & usage](https://docs.terratwin.com/content/guides/credits.md) for charging rules and examples.

## Build the request

We will build the request body one section at a time. Each step shows the complete JSON as it stands at that point, so you can see how the pieces fit together.

**1. Define the cargo**

Every calculation starts with a `cargo` object.
The only required cargo property is `weight`, which contains a positive `value` and a supported `unit`.

Start with this request body:

```json theme={null}
{
  "cargo": {
    "weight": {
      "value": 1,
      "unit": "METRIC_TONNE"
    }
  }
}
```

The weight should include the goods and packaging supplied by the shipper. It should not include carrier equipment such as pallets or shipping containers added after handover.

This minimal object is enough for a first calculation. For more representative defaults, you can also describe the cargo category, density characteristics, and climate-control requirements.

See the [Cargo guide](https://docs.terratwin.com/content/guides/cargo.md) for supported weight units, cargo categories, temperature control, density, and how cargo properties affect transport and hub defaults.

**2. Define the origin and destination**

Add top level `origin` and `destination` objects.
Each location needs a `type` and enough information for TerraTwin to resolve it.

For this tutorial, use structured address `PLACE` locations:

```json theme={null}
{
  "cargo": {
    "weight": {
      "value": 1,
      "unit": "METRIC_TONNE"
    }
  },
  "origin": {
    "type": "PLACE",
    "street": "Platz der Republik 1",
    "postcode": "11011",
    "city": "Berlin",
    "country": "DE"
  },
  "destination": {
    "type": "PLACE",
    "postcode": "SW1A 0AA",
    "city": "London",
    "country": "GB"
  }
}
```

`PLACE` is suitable for cities, addresses, postcodes, buildings, or coordinates. TerraTwin can also resolve purpose specific locations such as `AIRPORT`, `RAIL_YARD`, and `HARBOR`.

See the [Locations guide](https://docs.terratwin.com/content/guides/locations.md) for coordinates, structured and freeform addresses, postcodes, IATA airport codes, UN/LOCODEs, location types, and matching behavior.

**3. Create the transport chain**

Add a `transportChain` array to describe how the cargo moves from the origin to the destination.

A transport chain is ordered. Each element is either:

* A **transport operation**, which moves the cargo on one requested leg
* A **`HUB`**, which defines the boundary and handling point between legs

This shipment has only one leg, so the chain contains one road operation:

```json theme={null}
{
  "cargo": {
    "weight": {
      "value": 1,
      "unit": "METRIC_TONNE"
    }
  },
  "origin": {
    "type": "PLACE",
    "street": "Platz der Republik 1",
    "postcode": "11011",
    "city": "Berlin",
    "country": "Deutschland"
  },
  "destination": {
    "type": "PLACE",
    "postcode": "SW1A 0AA",
    "city": "London",
    "country": "GB"
  },
  "transportChain": [
    {
      "type": "ROAD"
    }
  ]
}
```

See the [Transport chains guide](https://docs.terratwin.com/content/guides/transport-chains.md) for single leg and multimodal chains, chain boundaries, and the difference between requested legs and the operations realized in the response.

**4. Choose the transport operation**

The `type` inside the transport chain element selects the operation for that leg.
This tutorial uses `ROAD`, which lets TerraTwin choose a default vehicle and operating configuration.

Use the guide for the operation you need when you are ready to add more detail:

> [card] ROAD
>
> Trucks, vans, vehicle size and structure, loading, empty running, energy, consumption data, and route options.
>
> [Read the Road transport guide](https://docs.terratwin.com/content/guides/road-transport.md)

> [card] RAIL
>
> Train selection, train weight, cargo mappings, traction energy, rail yards, and connector movements.
>
> [Read the Rail transport guide](https://docs.terratwin.com/content/guides/rail-transport.md)

> [card] WATER
>
> Vessels, capacity and size, containers, harbor selection, and navigation constraints.
>
> [Read the Water transport guide](https://docs.terratwin.com/content/guides/water-transport.md)

> [card] AIR
>
> Aircraft, airports, belly freight and freighters, route restrictions, and stopovers.
>
> [Read the Air transport guide](https://docs.terratwin.com/content/guides/air-transport.md)

> [card] UNKNOWN
>
> Use this only when the mode is genuinely unknown. TerraTwin tries fallback modes in order and selects the first one that succeeds.
>
> [Read the Unknown transport guide](https://docs.terratwin.com/content/guides/unknown-transport.md)

> [card] WEIGHTED\_MODES
>
> Use this when several known alternatives contribute to one leg. TerraTwin calculates every alternative and combines them using percentages that total `100`.
>
> [Read the Weighted modes transport guide](https://docs.terratwin.com/content/guides/weighted-modes-transport.md)

> [!NOTE]
>
> `UNKNOWN` and `WEIGHTED_MODES` solve different problems. `UNKNOWN` stops at the first feasible fallback mode; `WEIGHTED_MODES` calculates all supplied alternatives and returns their weighted combination.

## Send the calculation

In an application, you would normally send this JSON using the HTTP client for your programming language or framework. For this tutorial, use `curl` to make the same request directly.

Select the shell you use below. Each command sends the same HTTP request; only the quoting and line-continuation syntax differs between shells.

Replace `your-api-key` with your TerraTwin API key, then run the command.

> [tab] PowerShell 7.3+
>
> ```powershell theme={null}
> curl.exe --silent --show-error --fail-with-body `
>   --request POST `
>   --url "https://api.terratwin.com/api/v1/transportation/emissions/calculate" `
>   --header "Content-Type: application/json" `
>   --header "x-api-key: your-api-key" `
>   --data-raw '{
>     "cargo": {
>       "weight": {
>         "value": 1,
>         "unit": "METRIC_TONNE"
>       }
>     },
>     "origin": {
>       "type": "PLACE",
>       "street": "Platz der Republik 1",
>       "postcode": "11011",
>       "city": "Berlin",
>       "country": "Deutschland"
>     },
>     "destination": {
>       "type": "PLACE",
>       "postcode": "SW1A 0AA",
>       "city": "London",
>       "country": "GB"
>     },
>     "transportChain": [
>       {
>         "type": "ROAD"
>       }
>     ]
>   }'
> ```

> [tab] Windows PowerShell 5.1
>
> ```powershell theme={null}
> curl.exe --% --silent --show-error --fail-with-body --request POST --url "https://api.terratwin.com/api/v1/transportation/emissions/calculate" --header "Content-Type: application/json" --header "x-api-key: your-api-key" --data-raw "{\"cargo\":{\"weight\":{\"value\":1,\"unit\":\"METRIC_TONNE\"}},\"origin\":{\"type\":\"PLACE\",\"street\":\"Platz der Republik 1\",\"postcode\":\"11011\",\"city\":\"Berlin\",\"country\":\"Deutschland\"},\"destination\":{\"type\":\"PLACE\",\"postcode\":\"SW1A 0AA\",\"city\":\"London\",\"country\":\"GB\"},\"transportChain\":[{\"type\":\"ROAD\"}]}"
> ```

> [tab] Command Prompt
>
> ```bat theme={null}
> curl.exe --silent --show-error --fail-with-body ^
>   --request POST ^
>   --url "https://api.terratwin.com/api/v1/transportation/emissions/calculate" ^
>   --header "Content-Type: application/json" ^
>   --header "x-api-key: your-api-key" ^
>   --data-raw "{\"cargo\":{\"weight\":{\"value\":1,\"unit\":\"METRIC_TONNE\"}},\"origin\":{\"type\":\"PLACE\",\"street\":\"Platz der Republik 1\",\"postcode\":\"11011\",\"city\":\"Berlin\",\"country\":\"Deutschland\"},\"destination\":{\"type\":\"PLACE\",\"postcode\":\"SW1A 0AA\",\"city\":\"London\",\"country\":\"GB\"},\"transportChain\":[{\"type\":\"ROAD\"}]}"
> ```

> [tab] Bash or zsh
>
> ```bash theme={null}
> curl --silent --show-error --fail-with-body \
>   --request POST \
>   --url 'https://api.terratwin.com/api/v1/transportation/emissions/calculate' \
>   --header 'Content-Type: application/json' \
>   --header 'x-api-key: your-api-key' \
>   --data-raw '{
>     "cargo": {
>       "weight": {
>         "value": 1,
>         "unit": "METRIC_TONNE"
>       }
>     },
>     "origin": {
>       "type": "PLACE",
>       "street": "Platz der Republik 1",
>       "postcode": "11011",
>       "city": "Berlin",
>       "country": "Deutschland"
>     },
>     "destination": {
>       "type": "PLACE",
>       "postcode": "SW1A 0AA",
>       "city": "London",
>       "country": "GB"
>     },
>     "transportChain": [
>       {
>         "type": "ROAD"
>       }
>     ]
>   }'
> ```

> [!WARNING]
>
> Treat your API key as a secret. The inline value is convenient for this first test, but do not commit a real key to source control or share it in logs, screenshots, or support messages.

A successful request returns HTTP `200` and a JSON calculation result.

## Read the result

Start with these top-level response properties:

| Property | What it tells you |
| - | - |
| `totalEmissions.co2eGrams` | The total greenhouse gas emissions for transport operations and logistics hubs across the complete chain. |
| `transportEmissions.wtwCo2eGrams` | Well-to-wheel emissions from the transport operations. |
| `hubEmissions.co2eGrams` | Greenhouse gas emissions from logistics hubs included in the calculation. |
| `activityDistanceKm` | Total modelled distance across the transport operations. |
| `activityTonneKm` | Total transport activity in tonne-kilometres. |
| `transportChain` | The realized operation results, including defaults and any connector or hub operations TerraTwin added. |
| `creditCost` | Emissions API credits consumed by the calculation. |

> [!NOTE]
>
> One requested transport-chain element can produce several realized elements in the response. For example, an `AIR`, `RAIL`, or `WATER` leg between two general places can include first-mile road, a departure hub, the primary mode, an arrival hub, and last-mile road.

For every request field, response schema, enum, endpoint, and error model, see the [Emissions API reference](https://docs.terratwin.com/api-reference/calculate-transport-emissions.md).

## Extend the request to multiple legs

A chain can contain several transport operations, but each pair of requested operations must be separated by a `HUB` that defines where the first leg ends and the next begins.

For example, this chain moves cargo by water from the port of London Gateway \[`GBSHV`] to the port of Antwerp \[`BEANR`], handles it at the Antwerp maritime terminal, and then moves it by road to Frankfurt:

```json theme={null}
{
  "cargo": {
    "weight": {
      "value": 1,
      "unit": "METRIC_TONNE"
    }
  },
  "origin": {
    "type": "HARBOR",
    "unLoCode": "GBSHV"
  },
  "destination": {
    "type": "PLACE",
    "address": "Römerberg 27, 60311 Frankfurt am Main",
    "country": "DE"
  },
  "transportChain": [
    {
      "type": "WATER"
    }, {
      "type": "HUB",
      "hubType": "MARITIME_TERMINAL",
      "location": {
        "type": "HARBOR",
        "unLoCode": "BEANR"
      }
    }, {
      "type": "ROAD"
    }
  ]
}
```

The hub's `location` is both the destination boundary for the `WATER` leg and the origin boundary for the `ROAD` leg. The hub can also contribute cargo-handling emissions.

![](https://mintcdn.com/terratwin/0hbUXmLqgbSI5-VO/images/quick-start/london-to-frankfurt-light.png?fit=max\&auto=format\&n=0hbUXmLqgbSI5-VO\&q=85\&s=fa90bc7bab2274c0b393cc02ee42b994)

Sea transport from London Gateway to the Port of Antwerp, then by road to Frankfurt’s Römer

See the [Hubs guide](https://docs.terratwin.com/content/guides/hubs.md) for explicit and automatically inserted hubs, hub types, endpoint hubs, transition defaults, and controlling hub insertion.

> [!WARNING]
>
> A hub is not a transport movement. Do not put vehicle, distance, or energy properties on a `HUB`; configure those properties on the surrounding transport operations.

## Next steps

Use these guides as you replace defaults and model more complex shipments:

> [card] Emissions API
>
> * [Emissions API guide](https://docs.terratwin.com/content/guides/emissions-api.md) – endpoints, options, storing and retrieving results
> * [Credits & usage](https://docs.terratwin.com/content/guides/credits.md)

> [card] Shipment structure
>
> * [Cargo](https://docs.terratwin.com/content/guides/cargo.md)
> * [Locations](https://docs.terratwin.com/content/guides/locations.md)
> * [Transport chains](https://docs.terratwin.com/content/guides/transport-chains.md)
> * [Hubs](https://docs.terratwin.com/content/guides/hubs.md)

> [card] Transport operations
>
> * [Road transport](https://docs.terratwin.com/content/guides/road-transport.md)
> * [Rail transport](https://docs.terratwin.com/content/guides/rail-transport.md)
> * [Water transport](https://docs.terratwin.com/content/guides/water-transport.md)
> * [Air transport](https://docs.terratwin.com/content/guides/air-transport.md)
> * [Unknown transport](https://docs.terratwin.com/content/guides/unknown-transport.md)
> * [Weighted modes transport](https://docs.terratwin.com/content/guides/weighted-modes-transport.md)

> [card] Complete schema
>
> Use the [Emissions API reference](https://docs.terratwin.com/api-reference/calculate-transport-emissions.md) for exact field constraints, allowed values, complete response objects, error codes, and result-storage endpoints.

> [!TIP]
>
> Need only the routes and distances, without emissions? The [Distance API quick start](https://docs.terratwin.com/content/get-started/distance-api.md) uses the same request structure.

If a request fails, see [Errors and troubleshooting](https://docs.terratwin.com/content/get-started/quick-start.md#errors-and-troubleshooting).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.