使用 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