NAV Navbar
Logo
cURL Php JavaScript

Introduction

Welcome to the CarX API! You can use our API to access CarX API endpoints, which can get information on your vehicles and drivers enrolled in our database.

We have language bindings in Shell, Php, Python and JavaScript! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

Authentication

To authorize, pass the key in input JSON data:

[
  {
    "key": "<Your API KEY>"
  }
]

CarX uses API keys to allow access to the API. You can register a new CarX API key at our developer portal.

CarX expects for the API key to be included in the body all API requests to the server in a header that looks like the following:

"key": <Your CarX API Key>

Route Optimization

VRP

curl -X POST \
  https://api.carx.io/route \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
    "key": "<YOUR API KEY>",
    "type": 1,
    "methods": 0,
    "geocoding": 1,
    "directions": 0,
    "locations":
       [{"latitude":19.0895595,"longitude":72.8656144},
        {"latitude":19.1196773,"longitude":72.9050809},
        {"latitude":19.2183307,"longitude":72.9780896},
        {"latitude":18.9067031,"longitude":72.8147123},
        {"latitude":19.1182937,"longitude":73.0275874},
        {"latitude":19.0770644,"longitude":72.9989924},
        {"latitude":19.1827551,"longitude":72.8401539}]
}'
<?php

$request = new HttpRequest();
$request->setUrl('https://carx.io/dashboard/signup');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'content-type' => 'application/json'
));

$request->setBody('{
    "key": "<YOUR API KEY>",
    "type": 1,
    "methods": 0,
    "geocoding": 1,
    "directions": 0,
    "locations":
       [{"latitude":19.0895595,"longitude":72.8656144},
        {"latitude":19.1196773,"longitude":72.9050809},
        {"latitude":19.2183307,"longitude":72.9780896},
        {"latitude":18.9067031,"longitude":72.8147123},
        {"latitude":19.1182937,"longitude":73.0275874},
        {"latitude":19.0770644,"longitude":72.9989924},
        {"latitude":19.1827551,"longitude":72.8401539}]
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
var data = JSON.stringify({
  "key": "<YOUR API KEY>",
  "type": 1,
  "methods": 0,
  "geocoding": 1,
  "directions": 0,
  "locations": [
    {
      "latitude": 19.0895595,
      "longitude": 72.8656144
    },
    {
      "latitude": 19.1196773,
      "longitude": 72.9050809
    },
    {
      "latitude": 19.2183307,
      "longitude": 72.9780896
    },
    {
      "latitude": 18.9067031,
      "longitude": 72.8147123
    },
    {
      "latitude": 19.1182937,
      "longitude": 73.0275874
    },
    {
      "latitude": 19.0770644,
      "longitude": 72.9989924
    },
    {
      "latitude": 19.1827551,
      "longitude": 72.8401539
    }
  ]
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.carx.io/route");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");

xhr.send(data);

The above command returns JSON structured like this:

{
    "api_status": "success",
    "solution": {
        "distance_total(kms)": 94,
        "optimized_route": [
            {
                "address": "Chhatrapati Shivaji International Airport, Chhatrapati Shivaji International Airport Area, Vile Parle, Mumbai, Maharashtra 400099, India",
                "latitude": 19.0895595,
                "location_id": 0,
                "longitude": 72.8656144
            },
            {
                "address": "19, JVLR, MHADA Colony 19, Powai, Mumbai, Maharashtra 400076, India",
                "latitude": 19.1196773,
                "location_id": 1,
                "longitude": 72.9050809
            },
            {
                "address": "143/4, Sant Gora Kumbhar Marg, Kumbharwada, Somwari Bazar, Malad West, Mumbai, Maharashtra 400064, India",
                "latitude": 19.1827551,
                "location_id": 6,
                "longitude": 72.8401539
            },
            {
                "address": "Kapurbawdi Flyover, Srinagar Colony, Thane West, Thane, Maharashtra 400606, India",
                "latitude": 19.2183307,
                "location_id": 2,
                "longitude": 72.9780896
            },
            {
                "address": "A-523, S Central Rd, MIDC Industrial Area, Mahape, Navi Mumbai, Maharashtra 400701, India",
                "latitude": 19.1182937,
                "location_id": 4,
                "longitude": 73.0275874
            },
            {
                "address": "B2-8/16, Sector-16, Vashi, Navi Mumbai, Maharashtra 400703, India",
                "latitude": 19.0770644,
                "location_id": 5,
                "longitude": 72.9989924
            },
            {
                "address": "S&T Chowk, Army Area, Backbay Reclamation, Colaba, Mumbai, Maharashtra 400005, India",
                "latitude": 18.9067031,
                "location_id": 3,
                "longitude": 72.8147123
            },
            {
                "address": "Chhatrapati Shivaji International Airport, Chhatrapati Shivaji International Airport Area, Vile Parle, Mumbai, Maharashtra 400099, India",
                "latitude": 19.0895595,
                "location_id": 0,
                "longitude": 72.8656144
            }
        ]
    }
}

This endpoint solves for the vehicle routing problem.

HTTP Request

POST https://api.carx.io/route

Query Parameters

Parameter Required Description
key true Your personal API Key
type true Select type as 1
methods false Default is haversine distance. Set as 1 for real time road distance
geocoding false Default is off. Set as 1 for location address
directions false Default is off. Set as 1 for turn by turn directions coordinates
locations true Enter location array as latitude and longitide coordinates

CVRP

curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 4fb0323a-8970-ee4f-dbb3-ac912d489167" -d '{
  "key": "Your API KEY",
  "type": 2,
  "num_vehicles": 3,
  "vehicle_capacity": 25,
  "methods": 0,
  "geocoding": 0,
  "locations":[   
    {"latitude":12.927923,"longitude":77.6271040,"demand": 0},
    {"latitude":12.9081357,"longitude":77.6476079,"demand": 19},
    {"latitude":12.9165757,"longitude":77.6101163,"demand": 14},
    {"latitude":12.9729963,"longitude":77.6167062,"demand": 21},
    {"latitude":12.9718915,"longitude":77.6411544,"demand": 3},
    {"latitude":12.9509292,"longitude":77.6679292,"demand": 4}]
}' "https://api.carx.io/route"
<?php

$request = new HttpRequest();
$request->setUrl('https://api.carx.io/route');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'postman-token' => 'd9f67212-0f35-8059-45a0-12ef7a9804ec',
  'cache-control' => 'no-cache',
  'content-type' => 'application/json'
));

$request->setBody('{
  "key": "Your API KEY",
  "type": 2,
  "num_vehicles": 3,
  "vehicle_capacity": 25,
  "methods": 0,
  "geocoding": 0,
  "locations":[   
    {"latitude":12.927923,"longitude":77.6271040,"demand": 0},
    {"latitude":12.9081357,"longitude":77.6476079,"demand": 19},
    {"latitude":12.9165757,"longitude":77.6101163,"demand": 14},
    {"latitude":12.9729963,"longitude":77.6167062,"demand": 21},
    {"latitude":12.9718915,"longitude":77.6411544,"demand": 3},
    {"latitude":12.9509292,"longitude":77.6679292,"demand": 4}]
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
var data = JSON.stringify({
  "key": "Your API KEY",
  "type": 2,
  "num_vehicles": 3,
  "vehicle_capacity": 25,
  "methods": 0,
  "geocoding": 0,
  "locations": [
    {
      "latitude": 12.927923,
      "longitude": 77.627104,
      "demand": 0
    },
    {
      "latitude": 12.9081357,
      "longitude": 77.6476079,
      "demand": 19
    },
    {
      "latitude": 12.9165757,
      "longitude": 77.6101163,
      "demand": 14
    },
    {
      "latitude": 12.9729963,
      "longitude": 77.6167062,
      "demand": 21
    },
    {
      "latitude": 12.9718915,
      "longitude": 77.6411544,
      "demand": 3
    },
    {
      "latitude": 12.9509292,
      "longitude": 77.6679292,
      "demand": 4
    }
  ]
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.carx.io/route");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("postman-token", "afac2b73-6e08-fa4b-9609-66e052c84f5a");

xhr.send(data);

The above command returns JSON structured like this:

{
    "api_status": "success",
    "solution": {
        "all_routes": [
            {
                "Vehicle 0": {
                    "route": [
                        [
                            {
                                "latitude": 12.927923,
                                "location id": 0,
                                "longitude": 77.627104
                            },
                            {
                                "latitude": 12.9718915,
                                "location id": 4,
                                "longitude": 77.6411544
                            },
                            {
                                "latitude": 12.9729963,
                                "location id": 3,
                                "longitude": 77.6167062
                            },
                            {
                                "latitude": 12.927923,
                                "location id": 0,
                                "longitude": 77.627104
                            }
                        ]
                    ],
                    "route demand": 24,
                    "route distance": 12.91047700219058
                }
            },
            {
                "Vehicle 1": {
                    "route": [
                        [
                            {
                                "latitude": 12.927923,
                                "location id": 0,
                                "longitude": 77.627104
                            },
                            {
                                "latitude": 12.9509292,
                                "location id": 5,
                                "longitude": 77.6679292
                            },
                            {
                                "latitude": 12.9081357,
                                "location id": 1,
                                "longitude": 77.6476079
                            },
                            {
                                "latitude": 12.927923,
                                "location id": 0,
                                "longitude": 77.627104
                            }
                        ]
                    ],
                    "route demand": 23,
                    "route distance": 13.482022679344048
                }
            },
            {
                "Vehicle 2": {
                    "route": [
                        [
                            {
                                "latitude": 12.927923,
                                "location id": 0,
                                "longitude": 77.627104
                            },
                            {
                                "latitude": 12.9165757,
                                "location id": 2,
                                "longitude": 77.6101163
                            },
                            {
                                "latitude": 12.927923,
                                "location id": 0,
                                "longitude": 77.627104
                            }
                        ]
                    ],
                    "route demand": 14,
                    "route distance": 4.46422891270111
                }
            }
        ],
        "total_distance": 29
    }
}

This endpoint solves for the multiple vehicle routing problem.

HTTP Request

POST https://api.carx.io/route

Query Parameters

Parameter Required Description
key true Your personal API Key
type true Select type as 2
methods false Default is haversine distance. Set as 1 for real time road distance
geocoding false Default is off. Set as 1 for location address
locations true Enter location array as latitude and longitide coordinates
demands true Enter demands at each location node
num_vehicles true Enter number of vehicles
vehicle_capacity true Enter vehicle capacity

CVRPTW

curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 221b1d7c-80bb-8f99-b1d7-6d6ddd7c8b5e" -d '{
  "key": "Your API KEY",
  "type": 3,
  "geocoding":1,
  "methods": 0,
  "num_vehicles": 3,
  "vehicle_capacity": 100,
  "locations": [{"latitude":28.6415494,"longitude":77.2208123,"demands": 0, "start_times": 0,"end_times": 84000},
  {"latitude":286314512,"longitude":77.2166672,"demands": 45, "start_times": 5000,"end_times": 15000},
  {"latitude":28.5452912,"longitude":77.192323,"demands": 33, "start_times": 20000,"end_times": 35000},
  {"latitude":28.6159804,"longitude":77.2443823,"demands": 23, "start_times": 45600,"end_times": 68891},
  {"latitude":28.5558998,"longitude":77.2538509,"demands": 91, "start_times": 45800,"end_times": 81891},
  {"latitude":28.5842523,"longitude":77.1638282,"demands": 5, "start_times": 900,"end_times": 25000}]
}' "https://api.carx.io/route"
<?php

$request = new HttpRequest();
$request->setUrl('https://api.carx.io/route');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'postman-token' => 'baa7d641-b6f4-7783-5c8a-82ab5e8da642',
  'cache-control' => 'no-cache',
  'content-type' => 'application/json'
));

$request->setBody('{
  "key": "Your API KEY",
  "type": 3,
  "geocoding":1,
  "methods": 0,
  "num_vehicles": 3,
  "vehicle_capacity": 100,
  "locations": [{"latitude":28.6415494,"longitude":77.2208123,"demands": 0, "start_times": 0,"end_times": 84000},
  {"latitude":286314512,"longitude":77.2166672,"demands": 45, "start_times": 5000,"end_times": 15000},
  {"latitude":28.5452912,"longitude":77.192323,"demands": 33, "start_times": 20000,"end_times": 35000},
  {"latitude":28.6159804,"longitude":77.2443823,"demands": 23, "start_times": 45600,"end_times": 68891},
  {"latitude":28.5558998,"longitude":77.2538509,"demands": 91, "start_times": 45800,"end_times": 81891},
  {"latitude":28.5842523,"longitude":77.1638282,"demands": 5, "start_times": 900,"end_times": 25000}]
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
var data = JSON.stringify({
  "key": "Your API KEY",
  "type": 3,
  "geocoding": 1,
  "methods": 0,
  "num_vehicles": 3,
  "vehicle_capacity": 100,
  "locations": [
    {
      "latitude": 28.6415494,
      "longitude": 77.2208123,
      "demands": 0,
      "start_times": 0,
      "end_times": 84000
    },
    {
      "latitude": 286314512,
      "longitude": 77.2166672,
      "demands": 45,
      "start_times": 5000,
      "end_times": 15000
    },
    {
      "latitude": 28.5452912,
      "longitude": 77.192323,
      "demands": 33,
      "start_times": 20000,
      "end_times": 35000
    },
    {
      "latitude": 28.6159804,
      "longitude": 77.2443823,
      "demands": 23,
      "start_times": 45600,
      "end_times": 68891
    },
    {
      "latitude": 28.5558998,
      "longitude": 77.2538509,
      "demands": 91,
      "start_times": 45800,
      "end_times": 81891
    },
    {
      "latitude": 28.5842523,
      "longitude": 77.1638282,
      "demands": 5,
      "start_times": 900,
      "end_times": 25000
    }
  ]
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.carx.io/route");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("postman-token", "124c1a9f-769e-e78f-e8fd-c596e7b37d64");

xhr.send(data);

The above command returns JSON structured like this:

{
    "api_status": "success",
    "solution": {
        "all_routes": [
            {
                "Vehicle 0": {
                    "route": [
                        {
                            "address": "Pedestrian Overpass, Railway Colony, Paharganj, New Delhi, Delhi 110006, India",
                            "cumulative demand": 0,
                            "end time": 0,
                            "latitude": 28.6415494,
                            "location id": 0,
                            "longitude": 77.2208123,
                            "start time": 0
                        },
                        {
                            "address": "Can't find location name!",
                            "cumulative demand": 0,
                            "end time": 15000,
                            "latitude": 286314512,
                            "location id": 1,
                            "longitude": 77.2166672,
                            "start time": 5000
                        },
                        {
                            "address": "Main Building, IIT Delhi Main Rd, Indian Institute of Technology Delhi, Hauz Khas, New Delhi, Delhi 110016, India",
                            "cumulative demand": 45,
                            "end time": 86400,
                            "latitude": 28.6415494,
                            "location id": 0,
                            "longitude": 77.2208123,
                            "start time": 18537
                        }
                    ]
                }
            },
            {
                "Vehicle 1": {
                    "route": [
                        {
                            "address": "Pedestrian Overpass, Railway Colony, Paharganj, New Delhi, Delhi 110006, India",
                            "cumulative demand": 0,
                            "end time": 0,
                            "latitude": 28.6415494,
                            "location id": 0,
                            "longitude": 77.2208123,
                            "start time": 0
                        },
                        {
                            "address": "Can't find location name!",
                            "cumulative demand": 0,
                            "end time": 59099,
                            "latitude": 28.5558998,
                            "location id": 4,
                            "longitude": 77.2538509,
                            "start time": 45800
                        },
                        {
                            "address": "Main Building, IIT Delhi Main Rd, Indian Institute of Technology Delhi, Hauz Khas, New Delhi, Delhi 110016, India",
                            "cumulative demand": 91,
                            "end time": 86400,
                            "latitude": 28.6415494,
                            "location id": 0,
                            "longitude": 77.2208123,
                            "start time": 73101
                        }
                    ]
                }
            },
            {
                "Vehicle 2": {
                    "route": [
                        {
                            "address": "Pedestrian Overpass, Railway Colony, Paharganj, New Delhi, Delhi 110006, India",
                            "cumulative demand": 0,
                            "end time": 0,
                            "latitude": 28.6415494,
                            "location id": 0,
                            "longitude": 77.2208123,
                            "start time": 0
                        },
                        {
                            "address": "Can't find location name!",
                            "cumulative demand": 0,
                            "end time": 25000,
                            "latitude": 28.5842523,
                            "location id": 5,
                            "longitude": 77.1638282,
                            "start time": 900
                        },
                        {
                            "address": "Main Building, IIT Delhi Main Rd, Indian Institute of Technology Delhi, Hauz Khas, New Delhi, Delhi 110016, India",
                            "cumulative demand": 5,
                            "end time": 35000,
                            "latitude": 28.5452912,
                            "location id": 2,
                            "longitude": 77.192323,
                            "start time": 20000
                        },
                        {
                            "address": "Unnamed Road, Pragati Maidan, New Delhi, Delhi 110002, India",
                            "cumulative demand": 38,
                            "end time": 68891,
                            "latitude": 28.6159804,
                            "location id": 3,
                            "longitude": 77.2443823,
                            "start time": 45600
                        },
                        {
                            "address": "252K, Raja Dhirsain Marg, Sant Nagar, East of Kailash, New Delhi, Delhi 110065, India",
                            "cumulative demand": 61,
                            "end time": 86400,
                            "latitude": 28.6415494,
                            "location id": 0,
                            "longitude": 77.2208123,
                            "start time": 52500
                        }
                    ]
                }
            }
        ],
        "total_distance": 791
    }
}

This endpoint solves for the multiple vehicle routing problem with time window.

HTTP Request

POST https://api.carx.io/route

Query Parameters

Parameter Required Description
key true Your personal API Key
type true Select type as 3
methods false Default is haversine distance. Set as 1 for real time road distance
geocoding false Default is off. Set as 1 for location address
locations true Enter location array as latitude and longitide coordinates
demands true Enter demands at each location node
num_vehicles true Enter number of vehicles
vehicle_capacity true Enter vehicle capacity
start_times true Enter start time at each node
end_times true Enter end time at each node

Errors

The CarX API uses the following error codes:

Error Code Meaning
400 Bad Request – Failed to decode JSON object.
401 Unauthorized – Your API key is wrong
404 Not Found – URL not found! What you were looking for is just not there.