Delete trip

This document describes how to delete a trip. It assumes you have set up Fleet Engine. See Set up Fleet Engine.

Trip deletion basics

Your system may use Fleet Engine to delete a trip in the following situations:

  • To perform cleanup operations while testing Fleet Engine APIs.
  • To immediately delete a Trip that is no longer required.

To delete a trip, send a request using either gRPC or REST.

  • DeleteTrip() method: gRPC or REST
  • DeleteTripRequest message: gRPC only

Use the appropriate credentials for the service account of your project as described in Fleet Engine: Service account roles.

Example: delete trip

The following example demonstrates how to delete a trip in Fleet Engine.

static final String PROJECT_ID = "my-rideshare-co-gcp-project";
static final String TRIP_ID = "trip-8241890";

String tripName = "providers/" + PROJECT_ID + "/trips/" + TRIP_ID;

TripServiceBlockingStub tripService = TripServiceGrpc.newBlockingStub(channel);

// Delete trip request.
DeleteTripRequest deleteTripRequest = DeleteTripRequest.newBuilder()
    .setName(tripName)
    .build();

// Error handling.
try {
  tripService.deleteTrip(deleteTripRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case NOT_FOUND:            // The trip doesn't exist.
      break;
    case FAILED_PRECONDITION:  // Trip is active and assigned to a vehicle.
      break;
    case PERMISSION_DENIED:
      break;
  }
  return;
}

Handle errors

When deleting a trip, you might encounter a FAILED_PRECONDITION error, in which case the trip is active and assigned to a vehicle.
To proceed with the deletion, call UpdateTrip and update the trip_status to COMPLETE/CANCELED.

What's next