Example 6 – Integration with the Toll for Maps API
The Freight API service can be integrated with the Toll for Maps API, so in addition to the return of toll rates, the freight calculation will also be provided.
The process consists of simply adding the Freight API parameters to the body of the request to the Toll for Maps APIs.
You don’t need to include the parameter distance
, as the distance traveled will already be in the Directions API response.
The following example shows a request for a route between São Paulo – SP and Campinas – SP, to be traveled by a truck with 4 double axles, including calculation of tolls and freight (Cargo: Solid bulk / Type of operation: D).
Endpoint used:https://api.maplink.global/toll/v1/directions?vehicleType={TIPO_VEICULO} (Método: POST)
The body of the request must contain the Directions API response, plus the Freight API parameters, as shown in the example below:
{ //Resposta da Directions API "maplink": { "freight": { "operationType": [ "D" ], "goodsType": [ "GRANEL_SOLIDO" ], "axis": [ "4" ], "roundTrip": false, "backEmpty": false, "otherCosts": [ { "name": "ICMS", "type": "PERCENT", "value": "5" }, { "name": "Lucro", "type": "PERCENT", "value": "20" }, { "name": "TaxaFixa", "type": "FIXED", "value": "500" } ], "date": "2021-10-02" } } }
The full response can be found below:
{ "results": [ { "legs": [ { "tolls": [ { "id": "13", "name": "Pedágio - Campo Limpo", "address": "SP 348 - Rod. dos Bandeirantes", "city": "Campo Limpo", "state": { "name": "São Paulo", "code": "SP" }, "country": "Brasil", "concession": "Autoban", "direction": "NORTH", "coordinates": { "latitude": -23.3260346, "longitude": -46.8231453 }, "serviceTypes": [ { "serviceId": "48", "name": "Via Facil" }, { "serviceId": "35353480390470101", "name": "ANTTCODE" } ], "price": 31.80 }, { "id": "73", "name": "Pedágio - Valinhos Norte", "address": "SP 330 - Rod. Anhanguera Km 82", "city": "Valinhos", "state": { "name": "São Paulo", "code": "SP" }, "country": "Brasil", "concession": "Autoban", "direction": "NORTHWEST", "coordinates": { "latitude": -23.01295484, "longitude": -47.0230555 }, "serviceTypes": [ { "serviceId": "50", "name": "Via Facil" }, { "serviceId": "35353300820000101", "name": "ANTTCODE" } ], "price": 31.50 } ], "legTotalCost": 63.30 } ], "freight": { "source": "RESOLUÇÃO No 5.949, DE 13 DE JULHO DE 2021", "results": { "D": { "4": { "GRANEL_SOLIDO": { "value": 369.97, "otherCosts": { "ICMS": 18.50, "Lucro": 74.00, "TaxaFixa": 500 } } } } }, "minimumFreight": 369.97, "minimumFreightWithCosts": 962.47 }, "totalCost": 63.30, "routeFreightCost": 1025.77 } ] }