List vehicles

Use the ListVehicles method to find all vehicles that satisfy some specific request options. The ListVehicles method returns a paginated list of vehicles in the project that matches queries across vehicle fields.

Filter by vehicle attributes

You can also use this method to filter on vehicle attributes, which act as AND operator when used in conjunction with other field specifications. For details on filter query syntax, see Filtering: AIP-160 for examples. For details on creating vehicle attributes, see Vehicle attributes field in the Update vehicle fields guide.

List vehicle example

This example filters on both the vehicle_type and attributes fields using the filter string, showing only vehicles of type AUTO and obtaining the LUXURY value for the custom attribute of class.

Java

static final String PROJECT_ID = "project-id";

VehicleServiceBlockingStub vehicleService = VehicleService.newBlockingStub(channel);

String parent = "providers/" + PROJECT_ID;
ListVehiclesRequest listVehiclesRequest = ListVehiclesRequest.newBuilder()
    .setParent(parent)
    .addTripTypes(TripType.EXCLUSIVE)
    .addVehicleTypes(VehicleType.newBuilder().setCategory(VehicleType.Category.AUTO))
    .setFilter("attributes.on_trip=\"false\"")
    .setIncludeBackToBack(true) // Fleet Engine includes vehicles that are en route.
    .build();

// Error handling
// If matches are returned and the authentication passed, the request completed
// successfully

try {
  ListVehiclesResponse listVehiclesResponse =
      vehicleService.listVehicles(listVehiclesRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case NOT_FOUND:
      break;
    case PERMISSION_DENIED:
      break;
  }
  return;
}

REST

curl -X POST \
  "https://fleetengine.googleapis.com/v1/providers/project-id/vehicles:list" \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  --data-binary @- << EOM
{
  "vehicleTypes": [{"category": "AUTO"}],
  "filter": "attributes.class=\"LUXURY\"",
}
EOM

What's next