The following example shows how to use the Java gRPC library to delete a
vehicle.
staticfinalStringPROJECT_ID="my-delivery-co-gcp-project";staticfinalStringVEHICLE_ID="vehicle-8241890";StringvehicleName="providers/"+PROJECT_ID+"/vehicles/"+VEHICLE_ID;VehicleServiceBlockingStubvehicleService=VehicleService.newBlockingStub(channel);// Delete Vehicle requestDeleteVehicleRequestdeleteVehicleRequest=DeleteVehicleRequest.newBuilder().setName(vehicleName).build();try{vehicleService.deleteVehicle(deleteVehicleRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseNOT_FOUND:// The vehicle doesn't exist.break;caseFAILED_PRECONDITION:// There are trip(s) that reference vehicle.break;casePERMISSION_DENIED:break;}return;}
REST
The following example shows how to delete a vehicle from Fleet Engine using REST by
making a call to DeleteVehicle.
# DELETE https://fleetengine.googleapis.com/v1/providers/<project_id>/vehicles/<vehicleId># Set JWT, PROJECT_ID, and VEHICLE_ID in the local environmentcurl-XDELETE-H"Authorization: Bearer ${JWT}"\"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/vehicles/${VEHICLE_ID}"
If the delete operation is successful, the API returns an empty response.
Handle errors
When deleting a vehicle, you might encounter a FAILED_PRECONDITION
error, in which case there are trip(s) that reference the vehicle.
To proceed with the deletion:
Call SearchTrips to find trip(s) that reference the Vehicle.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-18 UTC."],[],[],null,["This document describes how to delete a vehicle. It assumes you\nhave set up Fleet Engine. See [Set up Fleet Engine](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet).\n\nVehicle deletion basics\n\nYour system may use Fleet Engine to delete a vehicle in the following situations:\n\n- To perform cleanup operations while testing Fleet Engine APIs.\n- To immediately delete a Vehicle that is no longer required.\n\nTo delete a vehicle, send a request using either gRPC or REST.\n\n- `DeleteVehicle()` method: [gRPC](/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1#maps.fleetengine.v1.VehicleService) or [REST](/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.vehicles/delete)\n- `DeleteVehicleRequest` message: [gRPC](/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1#deletevehiclerequest) only\n\nUse the appropriate credentials for the service account of your project as\ndescribed in [Fleet Engine: Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts).\n| **Note:** Fleet Engine automatically deletes a vehicle after it has been inactive for a period of time. See [Vehicle re-use](/maps/documentation/mobility/fleet-engine/essentials/vehicles#vehicle_re-use).\n\nExample: delete vehicle \n\nJava\n\n\nThe following example shows how to use the [Java gRPC library](/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.vehicles/delete) to delete a\nvehicle. \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String VEHICLE_ID = \"vehicle-8241890\";\n\n String vehicleName = \"providers/\" + PROJECT_ID + \"/vehicles/\" + VEHICLE_ID;\n\n VehicleServiceBlockingStub vehicleService = VehicleService.newBlockingStub(channel);\n\n // Delete Vehicle request\n DeleteVehicleRequest deleteVehicleRequest = DeleteVehicleRequest.newBuilder()\n .setName(vehicleName)\n .build();\n\n try {\n vehicleService.deleteVehicle(deleteVehicleRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND: // The vehicle doesn't exist.\n break;\n case FAILED_PRECONDITION: // There are trip(s) that reference vehicle.\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nREST\n\n\nThe following example shows how to delete a vehicle from Fleet Engine using REST by\nmaking a call to `DeleteVehicle`. \n\n # DELETE https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/vehicles/\u003cvehicleId\u003e\n # Set JWT, PROJECT_ID, and VEHICLE_ID in the local environment\n curl -X DELETE -H \"Authorization: Bearer ${JWT}\" \\\n \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/vehicles/${VEHICLE_ID}\"\n\nIf the delete operation is successful, the API returns an empty response.\n\nHandle errors\n\nWhen deleting a vehicle, you might encounter a `FAILED_PRECONDITION`\nerror, in which case there are trip(s) that reference the vehicle.\nTo proceed with the deletion:\n\n1. Call `SearchTrips` to find trip(s) that reference the Vehicle.\n2. Call `DeleteTrip` to delete each of the found trip.\n\n| **Warning:** Ensure that the found trip(s) are no longer required. Once deleted, trip(s) cannot be recovered.\n\nWhat's next\n\n- [Create an on-demand trip](/maps/documentation/mobility/fleet-engine/journeys/trips)"]]