使用 ListVehicles
方法查找满足某些特定请求选项的所有车辆。ListVehicles
方法会返回项目中与车辆字段中的查询匹配的车辆的分页列表。
按车辆属性过滤
您还可以使用此方法按车辆属性进行过滤,这些属性在与其他字段规范搭配使用时会用作 AND 运算符。如需详细了解过滤查询语法,请参阅过滤:AIP-160 中的示例。如需详细了解如何创建车辆属性,请参阅更新车辆字段指南中的车辆属性字段。
列出车辆示例
此示例使用 filter
字符串对 vehicle_type
和 attributes
字段进行过滤,仅显示“AUTO”类型的车辆,并获取 class
的自定义属性的 LUXURY 值。
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