列出車輛

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

後續步驟