For general information about how vehicles work in Fleet Engine, see the
following guides in the Fleet Engine essential section:

- [What is Fleet Engine?](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials.md.txt)
- [Introduction to vehicles](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/vehicles-intro.md.txt)

The documentation in this section describes how to create and manage vehicles in
Fleet Engine. You create vehicles in the Fleet Engine server environment to
mirror the actual vehicles in your real-world operation. Your Fleet Engine
vehicles should also correspond to those used in your backend system that you
use for vehicle assignments and routing.

You use a create method to create a vehicle resource, either using gRPC or REST.
The field names in this guide use gRPC notation for simplicity.

### On-demand trips

- [`CreateVehicleRequest`](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1.md.txt#maps.fleetengine.v1.CreateVehicleRequest) (gRPC)
- [`providers.vehicle.create`](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.vehicles/create.md.txt) (REST)
- `Vehicle` resource ([REST](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.vehicles.md.txt), [gRPC](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1.md.txt#maps.fleetengine.v1.Vehicle))

### Scheduled tasks

- [`CreateDeliveryVehicleRequest`](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/tasks/rpc/maps.fleetengine.delivery.v1.md.txt#maps.fleetengine.delivery.v1.CreateDeliveryVehicleRequest) (gRPC)
- [`providers.deliveryVehicles.create`](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/providers.deliveryVehicles/create.md.txt) (REST)
- `DeliveryVehicle` ([REST](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/providers.deliveryVehicles.md.txt), [gRPC](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/tasks/rpc/maps.fleetengine.delivery.v1.md.txt#maps.fleetengine.delivery.v1.DeliveryVehicle))

> [!NOTE]
> **Note:** The request messages and resource fields for the two Fleet Engine vehicle resources are largely parallel, even though some names vary between the two.

## Vehicle requests

For both on-demand and scheduled task capabilities, you create and update a
vehicle by issuing a request message with fields, summarized as follows:

1. **The parent**: a string associated with your Google Cloud project ID, used to populate the name field of the vehicle instance.
2. **The ID for the vehicle** : a unique string used to populate the `name`
   field of the vehicle.

   > [!NOTE]
   > **Note:** Vehicle ID strings have certain character restrictions. Avoid auto-incrementing IDs and ensure they contain no personally-identifiable information. For details on character restrictions, see the vehicle ID field for [CreateVehicleRequest](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1.md.txt#maps.fleetengine.v1.CreateVehicleRequest) or [CreateDeliveryVehicleRequest](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/issue-jwt.md.txt).

3. **A vehicle instance** with its required fields. These fields depend on the
   Fleet Engine capability you use.

The information in the request body varies with the nature of the request. See
those details under their respective guides.

### Authentication and authorization tokens

Requests to Fleet Engine must also provide the correct access credentials.
The examples in this guide have the following assumptions:

- gRPC examples assume the use of the [Authorization library](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/issue-jwt.md.txt#use-authorization) for Java.
- REST examples illustrate an HTTP request header, which must contain the field `Authorization` with a value of `Bearer <token>` where `<token>` is a [JSON Web Token you issue](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/issue-jwt.md.txt).

For more details, see the [Set up Fleet Engine](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet.md.txt) guides.

## Vehicle resource fields

A vehicle resource has the following kinds of fields:

- **Output only fields** . Fields that are set by the service as an output of another method and **cannot be directly set** . An important field of this type is the `name` field. Fleet Engine ignores any supplied value for the `name` field of the vehicle per guidance from Google AIP for [user-specified
  IDs](https://google.aip.dev/133#user-specified-ids). If you supply values for these fields, Fleet Engine returns an error.
- **Required fields**. Vehicles created in the on-demand trip service require that certain fields be set on creation. Vehicles created in the scheduled tasks service have no required vehicle resource fields.
- **Optional fields**. Both services have fields which you can set on creation or afterwards. These can be found in the respective reference guide for the service you use.

### Vehicle name (output only)

The `name` field is exactly the same for on-demand trips and scheduled task
services. Fleet Engine defines the field when you create the vehicle, based on
two fields you set at vehicle creation:

- **The parent** : a string associated with your Google Cloud project ID of the
  form `providers/{provider}` where `{provider}` is the ID of your Cloud
  project. Each vehicle you create for a given project will have the same
  parent path.

  The Cloud project you reference here must also contain the Fleet Engine
  service account roles for the service you use. See [Service Accounts](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts.md.txt) for
  a list of those service accounts. Fleet Engine does not support access from
  multiple Google Cloud projects.
- **The ID for the vehicle** , which must be unique across all vehicles in your
  fleet and be a valid Unicode string. This is the *resource ID* for the
  vehicle. Both on-demand trips and scheduled stops use this to associate a
  trip or a task with the vehicle that completes it.

In Google Cloud-based services, all APIs must represent resources as strings.
See [Resource naming in Fleet Engine](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials.md.txt#resource-naming) for more details.

### Unique entity identifiers

The format and value of the unique entity identifiers used in resource calls are
opaque to Fleet Engine. Make sure that the identifier does not contain any
personally-identifiable information (PII), such as the driver's phone number.

## Vehicle re-use

After a vehicle completes all stops for a given itinerary, it remains available
for re-use in Fleet Engine for 7 days, which means you can reuse a vehicle on
subsequent business days without having to create a new one. Each time you
reuse a vehicle, Fleet Engine resets its availability, at which point the
7-day countdown begins anew.

The recommended approach to keep a vehicle available in Fleet Engine is to
update its location at regular intervals. Updates to most other fields in the
`Vehicle` entity will also extend its life, provided that the new field value is
different from the existing one.

NOTE: Some fields on `Vehicle` entity like `device_settings` are purely debug
information that are not persisted by Fleet Engine. Updating them does not
extend the life of the `Vehicle` entity.

For improved system analytics, it's best to re-use the same driver-vehicle ID
pairing from day to day. Do this by using the same vehicle ID associated with
the driver for previous scheduled stops or on-demand trips.

## What's next

- [Create a vehicle for on-demand trips](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/vehicles/on-demand-create-vehicle.md.txt)
- [Create a vehicle for scheduled tasks](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/vehicles/scheduled-tasks-create-vehicle.md.txt)