列出车辆

使用 ListVehicles 方法查找满足某些特定条件的所有车辆 请求选项。ListVehicles 方法会返回分页的车辆列表 匹配所有车辆字段的查询。

按车辆属性过滤

您还可以使用此方法过滤车辆属性,这些属性的作用相当于 AND 关系 运算符。了解详情 如需了解过滤条件查询语法,请参阅过滤:AIP-160 获取示例。如需详细了解如何创建车辆属性,请参阅车辆 更新车辆字段指南中的“属性”字段部分。

列出车辆示例

此示例同时使用 vehicle_typeattributes 字段进行过滤, filter 字符串,仅显示 AUTO 类型的车辆,获取 LUXURY 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

后续步骤