Contents

Code Examples

Code Examples

This section provides practical code examples demonstrating how to use the Adastra Toll API in different programming languages. These examples will help you understand how to interact with the API and integrate it into your applications.

Toll Calculation Examples

JavaScript (fetch)

const url = 'https://api.adastrai.com/toll?key=YOUR_API_KEY';
const data = {
    "vehicleTypeId": "1",
    "lang": "en",
    "mapsource": "google",
    "expandTollsData": true,
    "departureTime": "2024-12-18T20:11:08.726Z",
    "steps": "40.90855,29.31515;40.90878,29.31577;40.90878,29.31578;40.90922,29.31678;..."
};

fetch(url, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => console.log(data))
.catch((error) => console.error('Error:', error));

Python (requests)

import requests
import json

url = 'https://api.adastrai.com/toll?key=YOUR_API_KEY'
data = {
    "vehicleTypeId": "1",
    "lang": "en",
    "mapsource": "google",
    "expandTollsData": True,
    "departureTime": "2024-12-18T20:11:08.726Z",
    "steps": "40.90855,29.31515;40.90878,29.31577;40.90878,29.31578;40.90922,29.31678;..."
}
headers = {'Content-Type': 'application/json'}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())

C# (HttpClient)

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

public class Example
{
    public static async Task Main(string[] args)
    {
        using (HttpClient client = new HttpClient())
        {
            string url = "https://api.adastrai.com/toll?key=YOUR_API_KEY";
            var data = new {
                 vehicleTypeId = "1",
                 lang = "en",
                 mapsource = "google",
                 expandTollsData = true,
                 departureTime = "2024-12-18T20:11:08.726Z",
                 steps = "40.90855,29.31515;40.90878,29.31577;40.90878,29.31578;40.90922,29.31678;..."
            };
            string jsonData = JsonConvert.SerializeObject(data);
            HttpContent content = new StringContent(jsonData, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(url, content);
            string responseContent = await response.Content.ReadAsStringAsync();
             Console.WriteLine(responseContent);
        }
    }
}

Reporting Endpoint Examples

JavaScript (fetch)

const url = 'https://api.adastrai.com/report?key=YOUR_API_KEY&secret=YOUR_SECRET_KEY&reportName=all&timeCriteria=d';

fetch(url, {
    method: 'GET',
})
.then(response => response.json())
.then(data => console.log(data))
.catch((error) => console.error('Error:', error));

Python (requests)

import requests
import json

url = 'https://api.adastrai.com/report?key=YOUR_API_KEY&secret=YOUR_SECRET_KEY&reportName=all&timeCriteria=d'

response = requests.get(url)
print(response.json())

C# (HttpClient)

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;

public class Example
{
    public static async Task Main(string[] args)
    {
        using (HttpClient client = new HttpClient())
        {
            string url = "https://api.adastrai.com/report?key=YOUR_API_KEY&secret=YOUR_SECRET_KEY&reportName=all&timeCriteria=d";
            HttpResponseMessage response = await client.GetAsync(url);
            string responseContent = await response.Content.ReadAsStringAsync();
             Console.WriteLine(responseContent);
        }
    }
}

Mapsource Parameter

The mapsource parameter in the Toll Calculation endpoint can take one of the following values:

  • "google": Google Maps
  • "tomtomv1": TomTom Maps V1
  • "tomtomv2": TomTom Orbis Maps V2

Important Considerations

  • Replace YOUR_API_KEY and YOUR_SECRET_KEY with your actual API key and secret key.
  • These examples provide a basic framework for interacting with the API. You may need to modify them based on your specific requirements.
  • Refer to the documentation for detailed explanations of each parameter and response field.