Create a vehicle for on-demand trips

To create a vehicle in Fleet Engine for on-demand trips, use the CreateVehicle endpoint with the CreateVehicleRequest. This endpoint requires an account with the Fleet Engine On-demand Admin role.

Fields for on-demand trip vehicles

When creating vehicles for on-demand trips, you must set required fields. You should also be familiar with how certain vehicle fields impact other functionality in Fleet Engine. See Update vehicle fields for that.

Required fields for on-demand trips

  • vehicle_state: Defaults to unknown, but should be set to ONLINE or OFFLINE. See information about setting the vehicle state field in Update vehicle fields.
  • supported_trip_types: Defaults to unknown, but should be set to SHARED, EXCLUSIVE, or both. See Trip types in the On-demand trips guide for details.
  • maximum_capacity: The number of passengers the vehicle can carry, which excludes the driver (by definition).
  • vehicle_type: Values are AUTO, TAXI, TRUCK, TWO_WHEELER, BICYCLE, or PEDESTRIAN. Can be used to filter vehicles for vehicle searches. This also influences ETA and route calculations. Fleet Engine provides routes and travel calculations that corresponds to the mode of travel based on the following vehicle type groups:
    • AUTO, TAXI or TRUCK: for example highways.
    • TWO_WHEELER: for example won't return routes where 2-wheelers aren't allowed.
    • BICYCLE: for example, bicycle paths.
    • PEDESTRIAN: for example pedestrian-only bridges and walkways.

Other fields

For other fields that you can set when creating a vehicle, see Update vehicle fields.

Vehicle creation example

The value returned from CreateVehicle is the created Vehicle entity.

Java

static final String PROJECT_ID = "project-id";

VehicleServiceBlockingStub vehicleService =
    VehicleService.newBlockingStub(channel);

String parent = "providers/" + PROJECT_ID;
Vehicle vehicle = Vehicle.newBuilder()
    .setVehicleState(VehicleState.OFFLINE)  // Initial state
    .addSupportedTripTypes(TripType.EXCLUSIVE)
    .setMaximumCapacity(4)
    .setVehicleType(VehicleType.newBuilder().setCategory(VehicleType.Category.AUTO))
    .addAttributes(VehicleAttribute.newBuilder()
        .setKey("on_trip").setValue("false"))  // Opaque to the Fleet Engine
    // Add .setBackToBackEnabled(true) to make this vehicle eligible for trip
    // matching while even if it is on a trip.  By default this is disabled.
    .build();

CreateVehicleRequest createVehicleRequest =
    CreateVehicleRequest.newBuilder()  // no need for the header
        .setParent(parent)
        .setVehicleId("vid-8241890")  // Vehicle ID assigned by Rideshare or Delivery Provider
        .setVehicle(vehicle)  // Initial state
        .build();

// In this case, the Vehicle is being created in the OFFLINE state and
// no initial position is being provided.  When the Driver App checks
// in with the Rideshare or Delivery Provider, the state can be set to ONLINE and
// the Driver App will update the Vehicle Location.

try {
  Vehicle createdVehicle =
      vehicleService.createVehicle(createVehicleRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case ALREADY_EXISTS:
      break;
    case PERMISSION_DENIED:
      break;
  }
  return;
}
// If no Exception, Vehicle created successfully.

REST

curl -X POST \
  "https://fleetengine.googleapis.com/v1/providers/project-id/vehicles?vehicleId=vid-8241890" \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  --data-binary @- << EOM
{
    "vehicleState": "OFFLINE",
    "supportedTripTypes": ["EXCLUSIVE"],
    "maximumCapacity": 4,
    "vehicleType": {"category": "AUTO"},
    "attributes": [{"key": "on_trip", "value": "false"}]
}
EOM

See providers.vehicles.create reference.

What's next