Get a vehicle

You can get a vehicle either from a server environment using gRPC or REST. This document provides examples for both.

Use gRPC to get a delivery vehicle

Java

The following example shows how to use the Java gRPC library to look up a vehicle.

  static final String PROJECT_ID = "my-delivery-co-gcp-project";
  static final String VEHICLE_ID = "vehicle-8241890";

  DeliveryServiceBlockingStub deliveryService =
    DeliveryServiceGrpc.newBlockingStub(channel);

  // Vehicle request
  String name = "providers/" + PROJECT_ID + "/deliveryVehicles/" + VEHICLE_ID;
  GetDeliveryVehicleRequest getVehicleRequest = GetDeliveryVehicleRequest.newBuilder()  // No need for the header
      .setName(name)
      .build();

  try {
    DeliveryVehicle vehicle = deliveryService.getDeliveryVehicle(getVehicleRequest);
  } catch (StatusRuntimeException e) {
    Status s = e.getStatus();
    switch (s.getCode()) {
       case NOT_FOUND:
         break;
       case PERMISSION_DENIED:
         break;
    }
    return;
  }

REST

To get a vehicle from a server environment using REST, make a call to GetVehicle as follows:

GET https://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles/<vehicleId>

  # Set JWT, PROJECT_ID, and VEHICLE_ID in the local environment
  curl -H "Authorization: Bearer ${JWT}" \
    "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}"

If the lookup is successful, the response body contains a vehicle entity.

What's next