Skip to navigation

Create & Register Vehicle

View as Markdown

Registers a new vehicle record (make, model, color, license number plate) and links it to a driver. If the request includes a driver Bearer token in the Authorization header, the vehicle is automatically associated with that driver without needing to pass driverId in the body.


Endpoint Overview

  • Method: POST

  • Route: /api/v1/vehicles

  • Authentication: Optional Bearer Token (Driver JWT) or via driverId in body

  • Content-Type: application/json


Request Headers

HeaderTypeRequiredDescription
AuthorizationstringNoOptional Format: Bearer (auto-links vehicle to authenticated driver)
Content-TypestringYesMust be application/json

Request Body Schema

FieldData TypeRequiredNullableAllowed Values / ConstraintsDescription
namestringYesNoMin length 1 (e.g. "Maruti Suzuki", "Honda", "Bajaj")Vehicle manufacturer / brand make
modelstringYesNoMin length 1 (e.g. "Swift Dzire", "Activa 6G", "Maxima")Vehicle model name
driverIdstringNoYesPrefixed with drv_ID of driver to link (auto-filled if Bearer token present)
colorstringNoYese.g. "White", "Silver", "Black"Vehicle paint color
number_platestringNoYese.g. "KA-01-AB-1234", "DL-04-XY-9876"Government registration plate number

Example Request Body

{
"name": "Maruti Suzuki",
"model": "Swift Dzire",
"color": "White",
"number_plate": "KA-01-AB-1234"
}

Response Body Schema (201 Created)

Top-Level KeyData TypeDescription
messagestringConfirmation message ("Vehicle created successfully")
vehicleobjectThe newly created vehicle record

vehicle Object Fields

FieldData TypeNullableAllowed Values / ConstraintsDescription
idstringNoPrefixed with veh_Unique vehicle ID
driverIdstringYesPrefixed with drv_Linked driver ID (or null if unlinked)
namestringNoStringVehicle make / brand
modelstringNoStringVehicle model
colorstringYesStringPaint color
number_platestringYesStringRegistration plate number
created_atstringNoISO 8601 TimestampRecord creation timestamp
updated_atstringNoISO 8601 TimestampLast update timestamp

Response Examples

1. 201 Created — Vehicle Registered Successfully

{
"message": "Vehicle created successfully",
"vehicle": {
"id": "veh_1a2b3c4d5e",
"driverId": "drv_8a7b6c5d4e",
"name": "Maruti Suzuki",
"model": "Swift Dzire",
"color": "White",
"number_plate": "KA-01-AB-1234",
"created_at": "2026-09-21T05:40:00.000Z",
"updated_at": "2026-09-21T05:40:00.000Z"
}
}

2. 400 Bad Request — Validation Error (Missing Required Fields)

{
"success": false,
"message": "Validation failed: name: Vehicle name is required, model: Vehicle model is required",
"errors": [
{
"field": "name",
"message": "Vehicle name is required"
},
{
"field": "model",
"message": "Vehicle model is required"
}
]
}

3. 500 Internal Server Error

{
"error": "Failed to create vehicle"
}

Status Codes Reference

HTTP Status CodeCondition
201 CreatedVehicle successfully inserted and linked in database.
400 Bad RequestMissing name or model fields in request body.
500 Internal Server ErrorServer or database insertion error.

Authentication

AuthorizationBearer

Bearer authentication of the form Bearer <token>, where token is your auth token.