Toll

Example 1 – Independent endpoint

In this example, we have a simple route that passes through the Itaquaquecetuba tollbooth. We will use the independent endpoint to calculate the tolls.

The parameter legs is an array of objects where each object represents a section of the route. In each leg, define the parameter points, which contains the coordinates that make up the route. In this case, we only have one leg which corresponds to the entire route.

At vehicleType we’ve decided that we want to do the route with a double-axle truck, TRUCK_WITH_TWO_DOUBLE_AXLES .

If you use the Trip API, the response obtained from Trip can be used as a request to the Toll API, simply by adding the parameter vehicleType to each leg.

Note: The independent endpoint is only recommended if you use third-party routers. If you use the Trip API, you can get the tolls in the same request. If you use Google’s Directions API, it is recommended that you use the Toll for Maps API.

In the next examples, integration with the Trip API will be used, but the response format will be the same for both the independent endpoint and Toll for Maps.

Below is the full request:

{
    "legs": [
        {
            "points": [
                {
                    "latitude": -23.465395,
                    "longitude": -46.375007
                },
                {
                    "latitude": -23.465957,
                    "longitude": -46.371015
                },
                {
                    "latitude": -23.467154,
                    "longitude": -46.36559
                }
            ],
            "vehicleType": "TRUCK_WITH_TWO_DOUBLE_AXLES"
        }
    ]
}

The response will come in JSON format.

At totalCost we have the total value of tolls on the entire route. Inside each leg an object tolls will be returned with the values and information of each toll on the corresponding stretch, and legTotalCost which shows the total value of tolls on that stretch. The field vehicleType will also be returned, indicating the vehicle used on that stretch.

Each object returned in tolls represents a toll and will contain the following information:

  • name – Toll name;
  • address – Toll address;
  • city – Toll city;
  • state – Object containing the name of the state (name) and its acronym (code);
  • country – Toll country;
  • concession – Concessionaire responsible for the toll;
  • coordinates – Coordinates (latitude and longitude) of the tollbooth;
  • price – Price per toll;
  • serviceTypes – Array with codes for integration with automatic payment systems. Currently only available in Brazil;
    • serviceId – Code for integration;
    • name – Description of the service code.

The full response can be found below:

{
    "legs": [
        {
            "tolls": [
                {
                    "id": "17",
                    "name": "Pedágio - Itaquaquecetuba Leste",
                    "address": "SP 070 - Rod. Ayrton Senna - Km 32,9",
                    "city": "Itaquaquecetuba",
                    "state": {
                        "name": "São Paulo",
                        "code": "SP"
                    },
                    "country": "Brasil",
                    "concession": "Ecopistas",
                    "direction": "EAST",
                    "coordinates": {
                        "latitude": -23.4656821,
                        "longitude": -46.3727036
                    },
                    "serviceTypes": [
                        {
                            "serviceId": "80",
                            "name": "Via Facil"
                        },
                        {
                            "serviceId": "35350700329000103",
                            "name": "ANTTCODE"
                        }
                    ],
                    "price": 10.40
                }
            ],
            "legTotalCost": 10.40,
            "vehicleType": "TRUCK_WITH_TWO_DOUBLE_AXLES"
        }
    ],
    "totalCost": 10.40
}