# Vehicles

Vehicles represent electric vehicles in the system. Each vehicle can have one or more access IDs (OCPP ID tags) associated with it, which can be used to represent cases where:

1. A vehicle has multiple charging ports with different MAC IDs
2. A vehicle MAC ID has changed over time, and you wish to maintain the connection to old charging sessions

Attaching an access ID to a vehicle can also be a way to associate an RFID card with the vehicle.

## GET /api/vehicles

Retrieve a list of all electric vehicles.

### Response

The JSON response will contain a `data` field with a list of vehicles, and a `pagination` field containing pagination details.

```ts
{
  data: {
    id: number;
    name: string | null;
    make: string | null;
    model: string | null;
    vin: string | null;
    licensePlate: string | null;
    hasTelematics: boolean;
    customer: {
      name: string;
    } | null;
    accessIds: {
      id: number;
      ocppIdTag: string;
      authorizationStatus: string; // Authorized | Revoked
    }[];
  }[];
  pagination: {
    hasNextPage: boolean;
    nextPageCursor: string | null;
  };
};
```

### Example request and response

Request:

```sh
curl "https://api.getflipturn.com/api/vehicles" -H "Authorization: Bearer {api_key}"
```

Response:

```js
{
  "data": [
    {
      "id": 20,
      "name": "Demo Tesla",
      "make": "Tesla",
      "model": "Model 3",
      "vin": "demo-vin-1",
      "licensePlate": "ABC123",
      "hasTelematics": false,
      "customer": {
        "name": "Electric Fleet Transportation"
      },
      "accessIds": [
        {
          "id": 123,
          "ocppIdTag": "id-tag-1",
          "authorizationStatus": "Authorized"
        }
      ]
    },
    {
      "id": 21,
      "name": "Vehicle 2",
      "make": null,
      "model": null,
      "vin": null,
      "licensePlate": null,
      "hasTelematics": false,
      "customer": null,
      "accessIds": []
    }
  ],
  "pagination": {
    "hasNextPage": false,
    "nextPageCursor": null
  }
}
```

## GET /api/vehicles/{id}

Retrieve the details for a specific vehicle.

### Response

```ts
{
  vehicle: {
    id: number;
    name: string | null;
    make: string | null;
    model: string | null;
    vin: string | null;
    licensePlate: string | null;
    hasTelematics: boolean;
    customer: {
      name: string;
    } | null;
    accessIds: {
      id: number;
      ocppIdTag: string;
      authorizationStatus: string; // Authorized | Revoked
    }[];
  }
};
```

### Example request and response

Request:

```sh
curl "https://api.getflipturn.com/api/vehicles/20" -H "Authorization: Bearer {api_key}"
```

Response:

```js
{
  "vehicle": {
    "id": 20,
    "name": "Demo Tesla",
    "make": "Tesla",
    "model": "Model 3",
    "vin": "demo-vin-1",
    "licensePlate": "ABC123",
    "hasTelematics": false,
    "customer": {
      "name": "Electric Fleet Transportation"
    },
    "accessIds": [
      {
        "id": 123,
        "ocppIdTag": "id-tag-1",
        "authorizationStatus": "Authorized"
      },
      {
        "id": 124,
        "ocppIdTag": "id-tag-2",
        "authorizationStatus": "Authorized"
      }
    ]
  }
}
```

## POST /api/vehicles

Create a new vehicle. When creating a vehicle, you can optionally associate one or more access IDs (OCPP ID tags) with it.

### Request Body

```ts
{
  vehicle: {
    name: string; // (required)
    make: string | null; // (optional)
    model: string | null; // (optional)
    vin: string | null; // (optional)
    licensePlate: string | null; // (optional)

    // (optional, creates a new customer if no existing customer is found with the same name, case insensitive)
    customer: {
      name: string;
    } | null;

    // (optional)
    accessIds: {
      ocppIdTag: string;
      authorizationStatus: string; // Authorized | Revoked (optional: defaults to Authorized)
    }[];
  }
}
```

### Response

```ts
{
  vehicle: {
    id: number;
    name: string | null;
    make: string | null;
    model: string | null;
    vin: string | null;
    licensePlate: string | null;
    hasTelematics: boolean;
    customer: {
      name: string;
    } | null;
    accessIds: {
      id: number;
      ocppIdTag: string;
      authorizationStatus: string; // Authorized | Revoked
    }[];
  }
};
```

### Example request and response

Request:

```sh
curl -X POST "https://api.getflipturn.com/api/vehicles" \
-H "Authorization: Bearer {api_key}" \
-H "Content-Type: application/json" \
-d '{
  "vehicle": {
    "name": "Vehicle 1",
    "make": "Tesla",
    "model": "Model 3",
    "vin": "demo-vehicle-vin",
    "licensePlate": "ABC123",
    "customer": {
      "name": "Electric Fleet Transportation"
    },
    "accessIds": [
      {
        "ocppIdTag": "ocpp-id-tag-1",
        "authorizationStatus": "Authorized"
      },
      {
        "ocppIdTag": "ocpp-id-tag-2",
        "authorizationStatus": "Revoked"
      }
    ]
  }
}'
```

Response:

```js
{
  "vehicle": {
    "id": 20,
    "name": "Vehicle 1",
    "make": "Tesla",
    "model": "Model 3",
    "vin": "demo-vehicle-vin",
    "licensePlate": "ABC123",
    "hasTelematics": false,
    "customer": {
      "name": "Electric Fleet Transportation"
    },
    "accessIds": [
      {
        "id": 123,
        "ocppIdTag": "ocpp-id-tag-1",
        "authorizationStatus": "Authorized"
      },
      {
        "id": 124,
        "ocppIdTag": "ocpp-id-tag-2",
        "authorizationStatus": "Revoked"
      }
    ]
  }
}
```

### Example request with minimal fields

Request:

```sh
curl -X POST "https://api.getflipturn.com/api/vehicles" \
-H "Authorization: Bearer {api_key}" \
-H "Content-Type: application/json" \
-d '{
  "vehicle": {
    "name": "Vehicle 1"
  }
}'
```

Response:

```js
{
  "vehicle": {
    "id": 20,
    "name": "Vehicle 1",
    "make": null,
    "model": null,
    "vin": null,
    "licensePlate": null,
    "hasTelematics": false,
    "customer": null,
    "accessIds": []
  }
}
```

## PATCH /api/vehicles/{id}

Update a vehicle.

### Request Body

For optional fields, explicitly providing `null` will delete the value. Omitting a field will leave it unchanged.

```ts
{
  vehicle: {
    name: string; // (optional)
    make: string | null; // (optional)
    model: string | null; // (optional)
    vin: string | null; // (optional)
    licensePlate: string | null; // (optional)
    customer: {
      name: string; // (optional, creates a new customer if no existing customer is found with the same name, case insensitive)
    } | null; // (optional, set to null to remove customer association)
  }
}
```

### Response

```ts
{
  vehicle: {
    id: number;
    name: string | null;
    make: string | null;
    model: string | null;
    vin: string | null;
    licensePlate: string | null;
    hasTelematics: boolean;
    customer: {
      name: string;
    } | null;
    accessIds: {
      id: number;
      ocppIdTag: string;
      authorizationStatus: string; // Authorized | Revoked
    }[];
  }
};
```

### Example request and response

Request:

```sh
curl -X PATCH "https://api.getflipturn.com/api/vehicles/20" \
-H "Authorization: Bearer {api_key}" \
-H "Content-Type: application/json" \
-d '{
  "vehicle": {
    "name": "Updated Vehicle Name",
    "make": "Toyota",
    "model": "Prius",
    "customer": {
      "name": "Electric Fleet Transportation"
    }
  }
}'
```

Response:

```js
{
  "vehicle": {
    "id": 20,
    "name": "Updated Vehicle Name",
    "make": "Toyota",
    "model": "Prius",
    "vin": "demo-vin-1",
    "licensePlate": "ABC123",
    "hasTelematics": false,
    "customer": {
      "name": "Electric Fleet Transportation"
    },
    "accessIds": [
      {
        "id": 123,
        "ocppIdTag": "id-tag-1",
        "authorizationStatus": "Authorized"
      }
    ]
  }
}
```

### Example request to remove fields

Request:

```sh
curl -X PATCH "https://api.getflipturn.com/api/vehicles/20" \
-H "Authorization: Bearer {api_key}" \
-H "Content-Type: application/json" \
-d '{
  "vehicle": {
    "name": "Updated Vehicle Name",
    "make": null,
    "model": null,
    "vin": null,
    "customer": null
  }
}'
```

Response:

```js
{
  "vehicle": {
    "id": 20,
    "name": "Updated Vehicle Name",
    "make": null,
    "model": null,
    "vin": null,
    "licensePlate": "ABC123",
    "hasTelematics": false,
    "customer": null,
    "accessIds": [
      {
        "id": 123,
        "ocppIdTag": "id-tag-1",
        "authorizationStatus": "Authorized"
      }
    ]
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-docs.getflipturn.com/vehicles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
