Multi-language examples showing how to enrich a TomTom route with real-time toll costs using the TollGuru API. Given a source and destination, the code fetches the route from TomTom, encodes it as a polyline, and queries TollGuru for toll costs across all payment types (tag, cash, credit card). Implementations in Python, JavaScript, Ruby, and PHP.
- Supported geographies — North America, Europe, Asia, Australia, Latin America
- Supported vehicle types — car, truck, motorcycle, bus, RV, and more
- Payment options — tag transponder, cash, licence plate, credit card, prepaid (in local currencies)
- Time-based tolls — pass
departure_timefor accurate rates on express lanes and time-of-day pricing - All toll system types — barrier, ticket system, and distance-based tolling
- Supported map services — edit the
sourceparam to use a different mapping platform - Truck parameters — height, weight, hazardous goods, tunnel category, etc.
- API parameter examples — full request body variations
- Client geocodes source/destination via TomTom Geocoding API (address → lat/lon)
- Client calls TomTom Routing API to get ordered route points
- Route points encoded into a Google-format polyline
- Polyline POSTed to TollGuru
/complete-polyline-from-mapping-serviceendpoint - TollGuru returns toll costs per payment type (tag, cash, credit card) per toll plaza
- All calls are synchronous HTTP — no server, no datastore, no queue
- Auth via API keys in environment variables (
TOMTOM_API_KEY,TOLLGURU_API_KEY) - Test harness reads source/destination pairs from CSV, writes results to CSV
- See docs/architecture.md for details
- TomTom API key — sign up at developer.tomtom.com, find your key at developer.tomtom.com/user/me/apps
- TollGuru API key — get a free key at platforms.mapup.ai/
- Language runtime for your chosen implementation:
- Python 3.8+
- Node.js 14+
- Ruby 2.6+
- PHP 7+ with cURL enabled
Set environment variables first:
export TOMTOM_API_KEY=your_tomtom_key
export TOLLGURU_API_KEY=your_tollguru_keyPython
cd python
pip install -r requirements.txt
python TomTom.pyJavaScript
cd javascript
npm install
node index.jsRuby
cd ruby
bundle install
ruby main.rbPHP
cd php
php php_curl_tomtom.phpPython — reads python/Testing/testCases.csv, writes testCases_result.csv
cd python/Testing
python Test_TomTom.pyRuby — reads ruby/TestCases/testCases.csv, writes testCases_output.csv
cd ruby/TestCases
ruby test_ruby.rbJavaScript and PHP have no automated test suite.
No server component. Scripts run as one-shot CLI tools. To deploy in CI or a scheduled job:
- Set
TOMTOM_API_KEYandTOLLGURU_API_KEYas secrets in your environment - Install dependencies for the target language
- Run the entry-point script for that language
All configuration is via environment variables. No config files.
| Variable | Required | Description |
|---|---|---|
TOMTOM_API_KEY |
Yes | TomTom Routing/Geocoding API key |
TOLLGURU_API_KEY |
Yes | TollGuru toll calculation API key |
Source/destination and vehicle type are set as constants in each implementation's entry-point file.
- No caching — every run makes live API calls
- No retry logic on transient failures
- PHP disables SSL peer/host verification (
CURLOPT_SSL_VERIFYPEER,CURLOPT_SSL_VERIFYHOSTset tofalse) - Ruby Gemfile locks to Ruby 2.6.10
- Single route per invocation; no batch mode in main scripts (test harness does batch via CSV)
- TollGuru returns costs for the first route leg only if multiple legs exist
- Supported geographies and vehicle types depend on TollGuru coverage — see country coverage and vehicle types
- docs/architecture.md — services, data flow, third-party dependencies, auth
- docs/runbook.md — failure recovery, rollback, monitoring
ISC License. Copyright 2020 TollGuru. See individual language READMEs for full text.