> For the complete documentation index, see [llms.txt](https://cde-inc.gitbook.io/cde-cad-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/fleet.md). Agents can also search and read this documentation through its [MCP server](https://cde-inc.gitbook.io/cde-cad-documentation/~gitbook/mcp).

# Fleet (Garage Kiosk)

Four endpoints for an in-game garage kiosk: list, add, check out and check in. The CAD owns **what** the fleet is and each vehicle's state; the game owns **where** it spawns, so nothing here carries coordinates.

## List the Fleet

```
GET /api/fivem/fleet
```

Optional `?departmentId=` scopes the list to one department.

### Response

```json
{
  "success": true,
  "total": 1,
  "vehicles": [{
    "id": "6a7a1623b68aafcb58624843",
    "unitId": "A-12",
    "label": "Interceptor 12",
    "plate": "LSPD-12",
    "spawnCode": "police3",
    "department": "LSPD",
    "departmentId": "6a73...",
    "type": "patrol",
    "station": "Mission Row",
    "requiredRank": "Sergeant",
    "requiredLevel": "Sergeant",
    "status": "available",
    "quantity": 25,
    "inUse": 13,
    "available": 12,
    "photo": "https://cdn.cdecad.com/public/communities/6a73.../records/apparatus/9f2c.png",
    "crewCount": 0,
    "odometerMeters": 184230,
    "engineHealth": 874,
    "bodyHealth": 912
  }]
}
```

* **`spawnCode`** is the FiveM model name. It is **`null` until a community fills it in**. It's a new field, so expect every vehicle to be `null` on day one. Grey out rows without one; nothing can spawn without it.
* **`status`** is `available`, `checked_out`, or `maintenance`. Both `out-of-service` and `maintenance` in the CAD collapse to `maintenance`, since a kiosk greys them out identically.
* **`department`** is the shortName, not an id. `departmentId` is included separately, but do not rely on it matching [`/departments`](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/departments.md) ids, because a vehicle may point at either a standalone department record or an embedded one.
* **`requiredRank`** is a department RANK name, or `null` for any officer. `requiredLevel` carries the same value under the older field name; the two never disagree. Rank order comes from [`/api/fivem/departments`](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/departments.md), whose `ranks[]` array is ordered **lowest to highest**, so `"Sergeant"` means Sergeant or above. Use that array to grey rows out client-side; the server enforces it regardless.
* **`quantity`**, **`inUse`** and **`available`** describe a row that stands for more than one identical vehicle - a department running 25 Durangos keeps one row rather than 25. `quantity` is how many the row represents, `inUse` how many are currently checked out, and `available` the difference. A row for a single vehicle sends `1 / 0 / 1` or `1 / 1 / 0`, so a kiosk that ignores all three reads exactly what it always did.
* **`status`** and `available` agree: a pool reads `checked_out` only once `available` hits `0`. Twelve spare Durangos are still `available` even with thirteen out.
* **`photo`** is a URL you can load directly, or `null`. The CAD stores it as an object reference rather than a URL, and expands it here so you never have to know that - do not try to construct one yourself, and do not cache it past the row you got it with.
* **`odometerMeters`**, **`engineHealth`**, **`bodyHealth`** are the maintenance telemetry accumulated from check-ins (see below). `odometerMeters` is the lifetime running total; the health values are the last reported 0-1000 pair, or `null` until a rig is first checked in with them.

{% hint style="info" %}
**Two ways a fleet has multiples, and they are not the same.**

A row with `quantity: 25` is one record: one plate, one set of telemetry, twenty-five vehicles. Telemetry is per row, so a pool's odometer is the pool's, not any one car's.

Twenty-five separate rows sharing a `spawnCode` are twenty-five records, each with its own `id`, `plate`, `status` and telemetry. Group those by `spawnCode` for display if you want one kiosk entry per model.

Use a pool for interchangeable vehicles nobody tracks individually, and separate rows when each unit's plate or condition matters.
{% endhint %}

## Add a Vehicle

```
POST /api/fivem/fleet
```

Adds a vehicle to a department's fleet from in game - a kiosk menu, a command, or your own script. The vehicle is created exactly the way **Add vehicle** on the website creates it: the plate shows up in plate lookups, the department is charged the community's registration and insurance fees, the first renewal is scheduled if the community bills renewals, and open fleet pages update without a reload.

{% hint style="warning" %}
Needs an API key with the `fleet:write` scope, and an `actingDiscordId`. Only the community's **owner** and **supervisors of the department being added to** (by that department's supervisor roles) can add. Other community admins are refused in game and told to add on the website: a Discord ID sent by a game server is not a website sign-in, so in game only the owner keeps admin standing. See [Permissions](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/permissions.md).
{% endhint %}

### Request Body

```json
{
  "actingDiscordId": "123456789012345678",
  "department": "LSPD",
  "plate": "LSPD 12",
  "spawnCode": "police3",
  "unitId": "A-12",
  "name": "Interceptor 12",
  "seats": 2,
  "type": "patrol"
}
```

| Field             | Required | Notes                                                                                                                 |
| ----------------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
| `actingDiscordId` | Yes      | The player adding the vehicle. `discordId` is also accepted.                                                          |
| `department`      | Yes      | Short name, full name or id. `departmentId` is also accepted.                                                         |
| `plate`           | Yes      | Up to 16 characters, stored in upper case.                                                                            |
| `spawnCode`       | Yes      | The FiveM model name, up to 64 characters. `model` is accepted as the same thing.                                     |
| `unitId`          | Yes      | Up to 32 characters. Unique within the department.                                                                    |
| `name`            | No       | Display name, up to 80 characters. The row's `label` falls back to the unit ID.                                       |
| `seats`           | No       | A whole number up to 99. Leave it out, or send `0`, for the department's default: 4 for fire, 2 for EMS, 1 otherwise. |
| `type`            | No       | Vehicle type. Defaults to `engine` for fire, `ambulance` for EMS and `patrol` otherwise.                              |

### Response

`201 Created`, with the same row [`GET /api/fivem/fleet`](#list-the-fleet) returns, so a kiosk can add it to its list without fetching again:

```json
{
  "success": true,
  "vehicle": {
    "id": "6a7a1623b68aafcb58624843",
    "unitId": "A-12",
    "label": "Interceptor 12",
    "plate": "LSPD 12",
    "spawnCode": "police3",
    "department": "LSPD",
    "type": "patrol",
    "status": "available",
    "quantity": 1,
    "inUse": 0,
    "available": 1
  }
}
```

The vehicle's notes record that it was added in game and by whom.

### Refusals

Every refusal carries `msg`, a sentence you can show the player as it is. A `400` also names the problem field in `field`.

| Status | When                                                                                       | Example `msg`                                                                                                                  |
| ------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `400`  | `actingDiscordId` is missing                                                               | `actingDiscordId is required for this action.`                                                                                 |
| `400`  | A required field is missing or too long                                                    | `A plate is required to add a vehicle to the fleet.`                                                                           |
| `400`  | No such department in this community                                                       | `There is no department called SAHP in this community.`                                                                        |
| `403`  | The player is not a member of the community                                                | `Officer is not a member of this community or could not be identified.`                                                        |
| `403`  | Not the owner, and not a supervisor of that department                                     | `Only LSPD's supervisors and the community's owner can add a vehicle to its fleet from in game.`                               |
| `403`  | A supervisor of another department                                                         | `You supervise SAFR, not LSPD. Only LSPD's supervisors and the community's owner can add a vehicle to its fleet from in game.` |
| `409`  | The plate is already in the fleet (case and spaces ignored, so `lspd12` matches `LSPD 12`) | `The plate LSPD 12 is already on Interceptor 12 (A-12) in the fleet.`                                                          |
| `409`  | The department already has that unit ID                                                    | `LSPD already has a vehicle with unit ID A-12.`                                                                                |

A `409` also returns `existing: { id, unitId, plate }` for the vehicle that already holds the plate or unit ID.

### Example

```lua
-- Server side. On FiveM a 4xx body arrives in the fourth callback argument
-- ("HTTP 409: {...}"), not the second.
PerformHttpRequest(CAD_URL .. '/api/fivem/fleet', function(status, body, _, errorData)
    local text = body or (errorData or ''):match('^HTTP %d+: (.*)$') or '{}'
    local ok, data = pcall(json.decode, text)
    data = ok and data or {}
    if status == 201 then
        print(('Added %s (%s) to the fleet'):format(data.vehicle.unitId, data.vehicle.plate))
    else
        print(('Not added: %s'):format(data.msg or ('HTTP ' .. tostring(status))))
    end
end, 'POST', json.encode({
    actingDiscordId = discordId,
    department = 'LSPD',
    plate = GetVehicleNumberPlateText(veh),
    spawnCode = 'police3',
    unitId = 'A-12',
    seats = GetVehicleModelNumberOfSeats(GetEntityModel(veh)),
}), { ['Content-Type'] = 'application/json', ['x-api-key'] = API_KEY })
```

## Check Out a Vehicle

```
POST /api/fivem/fleet/:id/checkout
```

{% hint style="warning" %}
Requires `actingDiscordId`, and enforces the community's fleet checkout level plus the vehicle's per-vehicle `requiredRank`. See [Permissions](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/permissions.md).
{% endhint %}

### Request Body

```json
{ "actingDiscordId": "123456789012345678" }
```

### Response

Check-out writes the same crew state as Begin Shift, so a vehicle taken at a kiosk shows the same crew in the CAD. Community admins bypass the rank gate.

Refuses with `409` when the vehicle is in maintenance or there is none left, and `403` when the officer does not meet `requiredRank`.

For a pool, "none left" means `available` has reached `0` - the other twelve are still takeable while thirteen are out. An officer already holding one of a row is refreshing rather than claiming a second, so that request goes through even when the pool is empty.

```json
{
  "success": false,
  "msg": "This vehicle requires Sergeant or above.",
  "requiredRank": "Sergeant",
  "yourRank": "Officer"
}
```

## Check In a Vehicle

```
POST /api/fivem/fleet/:id/checkin
```

{% hint style="warning" %}
Requires `actingDiscordId` (fleet checkin level). See [Permissions](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/permissions.md).
{% endhint %}

### Request Body

Send whatever condition data you measured this session. Everything except `actingDiscordId` is optional; a field you omit is treated as unknown and left untouched, never zeroed.

```json
{
  "actingDiscordId": "123...",
  "distanceMeters": 8420,
  "engineHealth": 874,
  "bodyHealth": 912
}
```

* **`distanceMeters`** is raw meters driven this session. The CAD **sums** it into the rig's lifetime `odometerMeters`, and keeps the per-session figure in the vehicle's note trail, so analytics can read either. GTA has no odometer, so this is how the running total is built.
* **`engineHealth`** and **`bodyHealth`** use GTA's 0-1000 scale (1000 = perfect), clamped to that range. The latest reported value wins.
* A rig that comes back with either health value under the community's service threshold (default **600**, set via `cadSettings.fleetHealthThreshold`) is flagged for service in the notes, with no form to fill in.

The older manual fields still work: `mileage` (number), `damaged` (boolean), `notes` (string). `damaged: true`, or health under the threshold, counts as "needs service".

### Response

Whether "needs service" also flips the rig to maintenance is the community's call, via **CAD Configuration → Fleet → auto status change** (default off, so a report never removes a vehicle on its own). The response carries the outcome:

```json
{
  "success": true,
  "damageReported": false,
  "needsService": true,
  "statusChanged": true,
  "odometerMeters": 192650,
  "engineHealth": 540,
  "bodyHealth": 780,
  "vehicle": { "...": "full fleet row" }
}
```
