تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يوضّح هذا المستند كيفية إنشاء مركبة من بيئة خادم باستخدام gRPC أو REST. يمكنك إنشاء مركبة من خلال Driver SDK، شرط أن تكون قد وفّرت التطبيق كبيئة موثوق بها باستخدام بيانات الاعتماد المناسبة.
للتعرّف على كيفية استخدام Driver SDK لإنشاء مركبات، يُرجى الاطّلاع على ما يلي:
لإنشاء مركبة جديدة من بيئة خادم، أرسِل طلب CreateDeliveryVehicle إلى Fleet Engine. استخدِم العنصر CreateDeliveryVehicleRequest لتحديد سمات مركبة التوصيل الجديدة.
حقول لمركبات المهام المجدوَلة
عند إنشاء DeliveryVehicle، يمكنك ضبط الحقول الاختيارية التالية:
attributes
last_location
type
لإنشاء مركبة بدون ضبط أي حقول اختيارية، يمكنك ترك الحقل
DeliveryVehicle بدون ضبط في 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
لإنشاء مركبة من بيئة خادم، عليك إجراء طلب HTTP REST
إلى CreateDeliveryVehicle:
يمثّل نص طلب 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 فارغًا. تستخرج المركبة التي تم إنشاؤها حديثًا معرّف مركبة من المَعلمة deliveryVehicleId في عنوان URL الخاص بطلب POST.
مثال:
# 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}"
تاريخ التعديل الأخير: 2025-08-16 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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)"]]