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;}
POST 本文は、作成する DeliveryVehicle エンティティを表します。次のオプション フィールドを指定できます。
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
フィールドを設定せずに車両を作成するには、POST リクエストの本文を空のままにします。新しく作成された車両は、POST URL の deliveryVehicleId パラメータから車両 ID を抽出します。
例:
# 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}"
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 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)"]]