Create Vehicle

Register a new vehicle in Niyantha TMS.

Base Information

Base URL

https://api.niyantha.in/

Authentication

Bearer Token

Use the token returned by account login

Request

HTTP Request

POST /api/v1/session/vehicles
Host: api.niyantha.in
Authorization: Bearer <token>
Content-Type: application/json

{
  "type": "scooter",
  "make": "tvs",
  "model_name": "speedo",
  "year": 2023,
  "registration_file_id": 22,
  "registration_number": "KA20MD8198",
  "current_location_latitude": 13.3409,
  "current_location_longitude": 74.7421,
  "transport_state_permissions": ["karnataka"],
  "all_india_permit": false,
  "is_commercial": true,
  "status": "active"
}

Request Parameters

ParameterTypeRequiredDescription
typestringYesVehicle type (car, truck, scooter, etc.)
makestringYesManufacturer of the vehicle
model_namestringYesModel of the vehicle
yearintegerYesManufacturing year
registration_file_idintegerYesID of the uploaded registration document file
registration_numberstringYesVehicle registration number
current_location_latitudefloatYesCurrent latitude of the vehicle
current_location_longitudefloatYesCurrent longitude of the vehicle
transport_state_permissionsarrayNoList of states where vehicle has transport permits
all_india_permitbooleanNoWhether the vehicle has all-India permit
is_commercialbooleanNoWhether the vehicle is used commercially
statusstringNoInitial status of the vehicle (active, inactive, maintenance)

Response

Success Response (200 OK)

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 31,
  "type": "scooter",
  "make": "tvs",
  "model": "speedo",
  "year": 2023,
  "registration_file_id": 22,
  "registration_number": "KA20MD8198",
  "current_location_latitude": 13.3409,
  "current_location_longitude": 74.7421,
  "current_location_measured_at": 1746260005,
  "transport_state_permissions": ["karnataka"],
  "all_india_permit": false,
  "is_commercial": true,
  "is_verified": false,
  "status": "active",
  "network_id": null
}

Response Fields

FieldTypeDescription
idintegerUnique identifier for the vehicle
current_location_measured_atintegerUnix timestamp of when location was measured
is_verifiedbooleanVerification status of the vehicle documents
network_idinteger | nullID of the network this vehicle belongs to (if any)

Error Responses

400 Bad Request

{
  "error": "validation_error",
  "message": "Validation failed",
  "details": {
    "registration_number": ["Invalid registration number format"]
  }
}

401 Unauthorized

{
  "error": "unauthorized",
  "message": "Invalid or missing authentication credentials"
}

404 Not Found

{
  "error": "not_found",
  "message": "Registration file with ID 22 not found"
}

Code Sample

fetch('https://api.niyantha.in/api/v1/session/vehicles', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    type: "scooter",
    make: "tvs",
    model_name: "speedo",
    year: 2023,
    registration_file_id: 22,
    registration_number: "KA20MD8198",
    current_location_latitude: 13.3409,
    current_location_longitude: 74.7421,
    transport_state_permissions: ["karnataka"],
    all_india_permit: false,
    is_commercial: true,
    status: "active"
  })
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));