Utwórz pojazd dostawczy do realizacji zaplanowanych zadań
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Z tego dokumentu dowiesz się, jak utworzyć pojazd w środowisku serwera za pomocą gRPC lub REST. Możesz utworzyć pojazd za pomocą pakietu Driver SDK, pod warunkiem że aplikacja została skonfigurowana jako zaufane środowisko przy użyciu odpowiednich danych logowania.
Aby dowiedzieć się, jak używać pakietu Driver SDK do tworzenia pojazdów, zapoznaj się z tymi materiałami:
Aby utworzyć nowy pojazd w środowisku serwera, wyślij CreateDeliveryVehicleżądanie do Fleet Engine. Użyj obiektu CreateDeliveryVehicleRequest, aby zdefiniować atrybuty nowego pojazdu dostawczego.
Pola pojazdów w zaplanowanych zadaniach
Podczas tworzenia DeliveryVehicle możesz ustawić te opcjonalne pola:
attributes
last_location
type
Aby utworzyć pojazd bez ustawiania żadnych pól opcjonalnych, możesz pozostawić pole DeliveryVehicle bez ustawionej wartości w CreateDeliveryVehicleRequest.
staticfinalStringPROJECT_ID="my-delivery-co-gcp-project";staticfinalStringVEHICLE_ID="vehicle-8241890";// Avoid auto-incrementing IDs.DeliveryServiceBlockingStubdeliveryService=DeliveryServiceGrpc.newBlockingStub(channel);// Vehicle settingsStringparent="providers/"+PROJECT_ID;DeliveryVehiclevehicle=DeliveryVehicle.newBuilder().addAttributes(DeliveryVehicleAttribute.newBuilder().setKey("route_number").setValue("1"))// Opaque to the Fleet Engine.build();// Vehicle requestCreateDeliveryVehicleRequestcreateVehicleRequest=CreateDeliveryVehicleRequest.newBuilder()// No need for the header.setParent(parent).setDeliveryVehicleId(VEHICLE_ID)// Vehicle ID assigned by the Provider.setDeliveryVehicle(vehicle).build();// Error handling// If Fleet Engine does not have vehicle with that ID and the credentials of the// requestor pass, the service creates the vehicle successfully.try{DeliveryVehiclecreatedVehicle=deliveryService.createDeliveryVehicle(createVehicleRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseALREADY_EXISTS:break;casePERMISSION_DENIED:break;}return;}
REST
Aby utworzyć pojazd w środowisku serwera, wywołaj interfejs API REST HTTP CreateDeliveryVehicle:
Treść żądania POST reprezentuje encję DeliveryVehicle, która ma zostać utworzona. Możesz określić te pola opcjonalne:
attributes
lastLocation
type
# Set $JWT, $PROJECT_ID, and $VEHICLE_ID in the local# environmentcurl-XPOST"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles?deliveryVehicleId=${VEHICLE_ID}"\
-H"Content-type: application/json"\
-H"Authorization: Bearer ${JWT}"\
--data-binary@- << EOM{"attributes":[{"key":"model","value":"sedan"}],"lastLocation":{"location":{"latitude":12.1,"longitude":14.5}}}EOM
Aby utworzyć pojazd bez ustawiania żadnych pól, pozostaw treść żądania POST pustą. Nowo utworzony pojazd wyodrębnia następnie identyfikator pojazdu z parametru deliveryVehicleId w adresie URL żądania POST.
Przykład:
# Set $JWT, $PROJECT_ID, and $VEHICLE_ID in the local# environmentcurl-XPOST"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles?deliveryVehicleId=${VEHICLE_ID}"\
-H"Content-type: application/json"\
-H"Authorization: Bearer ${JWT}"
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-08-16 UTC."],[[["\u003cp\u003eThis documentation outlines how to create a vehicle using gRPC or REST from a server environment or the Driver SDK (if provisioned as a trusted environment).\u003c/p\u003e\n"],["\u003cp\u003eWhen creating a vehicle, you can optionally set \u003ccode\u003eattributes\u003c/code\u003e, \u003ccode\u003elast_location\u003c/code\u003e, and \u003ccode\u003etype\u003c/code\u003e fields using the \u003ccode\u003eCreateDeliveryVehicle\u003c/code\u003e request.\u003c/p\u003e\n"],["\u003cp\u003eCreating a vehicle requires a \u003ccode\u003eCreateDeliveryVehicleRequest\u003c/code\u003e object with a defined parent, vehicle ID, and optional vehicle attributes.\u003c/p\u003e\n"],["\u003cp\u003eFleet Engine provides libraries and endpoints for vehicle creation using Java gRPC or REST API calls with necessary authorization.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid errors, do not set read-only or updatable fields when creating the vehicle; these can be modified using \u003ccode\u003eUpdateDeliveryVehicle\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["| **Note:** **Before constructing a vehicle request** , read the requirements under [Vehicle requests](/maps/documentation/mobility/fleet-engine/essentials/vehicles#vehicle_requests) in the Introduction.\n\nThis document describes how to create a vehicle from a server environment using\neither gRPC or REST. You can create a vehicle from the Driver SDK, provided\nyou have provisioned the app as a trusted environment using the appropriate\ncredentials.\n\nTo understand how to use the Driver SDK to create vehicles, see the following:\n\n- [Driver SDK](/maps/documentation/mobility/driver-sdk/scheduled) for scheduled tasks\n- [Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts) under **Fleet Engine essentials**.\n\nTo create a new vehicle from a server environment, make a\n`CreateDeliveryVehicle` request to Fleet Engine. Use the\n`CreateDeliveryVehicleRequest` object to define the attributes of the new\ndelivery vehicle.\n\nFields for scheduled tasks vehicles\n\nWhen creating a `DeliveryVehicle`, you set the following optional fields:\n\n- `attributes`\n- `last_location`\n- `type`\n\n| **Important:** Don't set any other fields. If you do, Fleet Engine returns an error because those fields are either read-only or can only be updated with a call to `UpdateDeliveryVehicle`.\n\nTo create a vehicle without setting any optional fields, you can leave the\n`DeliveryVehicle` field unset in the `CreateDeliveryVehicleRequest`.\n\nCreate vehicle example\n\nYou can use the [Java gRPC library](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-tasks#java) to create a vehicle, or REST. \n\nJava \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String VEHICLE_ID = \"vehicle-8241890\"; // Avoid auto-incrementing IDs.\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Vehicle settings\n String parent = \"providers/\" + PROJECT_ID;\n DeliveryVehicle vehicle = DeliveryVehicle.newBuilder()\n .addAttributes(DeliveryVehicleAttribute.newBuilder()\n .setKey(\"route_number\").setValue(\"1\")) // Opaque to the Fleet Engine\n .build();\n\n // Vehicle request\n CreateDeliveryVehicleRequest createVehicleRequest =\n CreateDeliveryVehicleRequest.newBuilder() // No need for the header\n .setParent(parent)\n .setDeliveryVehicleId(VEHICLE_ID) // Vehicle ID assigned by the Provider\n .setDeliveryVehicle(vehicle)\n .build();\n\n // Error handling\n // If Fleet Engine does not have vehicle with that ID and the credentials of the\n // requestor pass, the service creates the vehicle successfully.\n\n try {\n DeliveryVehicle createdVehicle =\n deliveryService.createDeliveryVehicle(createVehicleRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case ALREADY_EXISTS:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nREST\n\nTo create a vehicle from a server environment, make an HTTP REST call\nto `CreateDeliveryVehicle`: \n\n POST https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/deliveryVehicles?deliveryVehicleId=\u003cid\u003e\n\nThe POST body represents the `DeliveryVehicle` entity to be created. You can\nspecify the following optional fields:\n\n- `attributes`\n- `lastLocation`\n- `type`\n\n # Set $JWT, $PROJECT_ID, and $VEHICLE_ID in the local\n # environment\n curl -X POST \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles?deliveryVehicleId=${VEHICLE_ID}\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"attributes\": [{\"key\": \"model\", \"value\": \"sedan\"}],\n \"lastLocation\": {\"location\": {\"latitude\": 12.1, \"longitude\": 14.5}}\n }\n EOM\n\nTo create a vehicle without setting any fields, leave the body of the POST\nrequest empty. The newly-created vehicle then extracts a vehicle ID from the\n`deliveryVehicleId` parameter in the POST URL.\n\nExample: \n\n # Set $JWT, $PROJECT_ID, and $VEHICLE_ID in the local\n # environment\n curl -X POST \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles?deliveryVehicleId=${VEHICLE_ID}\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\"\n\nWhat's next\n\n- [Update delivery vehicle fields](/maps/documentation/mobility/fleet-engine/essentials/vehicles/scheduled-tasks-vehicle-fields)"]]