Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Ce document explique comment créer un lot de tâches à partir d'un environnement de serveur à l'aide de gRPC ou de REST. Pour en savoir plus sur la création de tâches, consultez les pages suivantes :
Lorsque vous créez des tâches par lot, chaque élément CreateTasksRequest dans requests doit respecter les mêmes règles de validation qu'une requête CreateTask pour une seule tâche, à l'exception des champs parent et header, qui sont facultatifs.
Si elles sont définies, elles doivent être identiques à leurs champs respectifs au niveau supérieur BatchCreateTasksRequest.
Pour en savoir plus, consultez la documentation de référence de l'API pour BatchCreateTasks pour gRPC ou REST.
Champs de lot obligatoires
Champ
Valeur
requêtes
Array<CreateTasksRequest>
Champs facultatifs des tâches par lot
Champ
Valeur
en-tête
DeliveryRequestHeader
Créer un lot de tâches
Les exemples suivants montrent comment créer une tâche de retrait et une tâche de livraison à l'aide de la bibliothèque gRPC Java ou comment effectuer une requête HTTP REST vers BatchCreateTask. Pour connaître la syntaxe JWT correcte, consultez Éléments JWT.
gRPC
staticfinalStringPROJECT_ID="my-delivery-co-gcp-project";DeliveryServiceBlockingStubdeliveryService=DeliveryServiceGrpc.newBlockingStub(channel);// Delivery Task settingsTaskdeliveryTask=Task.newBuilder().setType(Task.Type.DELIVERY).setState(Task.State.OPEN).setTrackingId("delivery-tracking-id").setPlannedLocation(// Grand Indonesia East MallLocationInfo.newBuilder().setPoint(LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826))).setTaskDuration(Duration.newBuilder().setSeconds(2*60)).build();// Delivery Task requestCreateTaskRequestcreateDeliveryTaskRequest=CreateTaskRequest.newBuilder()// No need for the header or parent fields.setTaskId("task-8312508")// Task ID assigned by the Provider.setTask(deliveryTask)// Initial state.build();// Pickup Task settingsTaskpickupTask=Task.newBuilder().setType(Task.Type.PICKUP).setState(Task.State.OPEN).setTrackingId("pickup-tracking-id").setPlannedLocation(// Grand Indonesia East MallLocationInfo.newBuilder().setPoint(LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826))).setTaskDuration(Duration.newBuilder().setSeconds(2*60)).build();// Pickup Task requestCreateTaskRequestcreatePickupTaskRequest=CreateTaskRequest.newBuilder()// No need for the header or parent fields.setTaskId("task-8241890")// Task ID assigned by the Provider.setTask(pickupTask)// Initial state.build();// Batch Create Tasks settingsStringparent="providers/"+PROJECT_ID;// Batch Create Tasks requestBatchCreateTasksRequestbatchCreateTasksRequest=BatchCreateTasksRequest.newBuilder().setParent(parent).addRequests(createDeliveryTaskRequest).addRequests(createPickupTaskRequest).build();// Error handling// If Fleet Engine does not have any task(s) with these task ID(s) and the// credentials of the requestor pass, the service creates the task(s)// successfully.try{BatchCreateTasksResponsecreatedTasks=deliveryService.batchCreateTasks(batchCreateTasksRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseALREADY_EXISTS:break;casePERMISSION_DENIED:break;}return;}
REST
Pour créer une tâche de livraison et une tâche d'enlèvement à partir d'un environnement serveur, effectuez un appel HTTP REST à BatchCreateTasks :
L'en-tête de la requête doit contenir un champ Authorization avec la valeur Bearer <token>, où <token> est émis par votre serveur conformément aux consignes décrites dans Rôles du compte de service et Jetons Web JSON.
Le corps de la requête doit contenir une entité BatchCreateTasksRequest.
Exemple de commande curl :
# Set $JWT, $PROJECT_ID, $DELIVERY_TRACKING_ID, $DELIVERY_TASK_ID,# $PICKUP_TRACKING_ID, and $PICKUP_TASK_ID in the local environment
curl-XPOST"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks:batchCreate"\-H"Content-type: application/json"\-H"Authorization: Bearer ${JWT}"\--data-binary@- << EOM
{"requests":[{"taskId":"${DELIVERY_TASK_ID}",
"task":{"type":"DELIVERY",
"state":"OPEN",
"trackingId":"${DELIVERY_TRACKING_ID}",
"plannedLocation":{"point":{"latitude":-6.195139,
"longitude":106.820826
}},
"taskDuration":"90s"}},
{"taskId":"${PICKUP_TASK_ID}",
"task":{"type":"PICKUP",
"state":"OPEN",
"trackingId":"${PICKUP_TRACKING_ID}",
"plannedLocation":{"point":{"latitude":-6.195139,
"longitude":106.820826
}},
"taskDuration":"90s"}}]}
EOM
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/05 (UTC)."],[[["\u003cp\u003eThis document explains how to create multiple tasks at once (batch creation) using the Fleet Engine Delivery API.\u003c/p\u003e\n"],["\u003cp\u003eYou can create tasks in batches by sending a \u003ccode\u003eBatchCreateTasksRequest\u003c/code\u003e containing multiple \u003ccode\u003eCreateTaskRequest\u003c/code\u003e objects.\u003c/p\u003e\n"],["\u003cp\u003eExamples are provided for creating tasks in batches using both gRPC and REST, including code snippets and a sample \u003ccode\u003ecurl\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eWhen creating tasks in batches, certain fields are required (\u003ccode\u003erequests\u003c/code\u003e) while others are optional (\u003ccode\u003eheader\u003c/code\u003e, inheriting from top-level request if present).\u003c/p\u003e\n"],["\u003cp\u003eEach \u003ccode\u003eCreateTasksRequest\u003c/code\u003e element in the batch follows the same validation rules as individual task creation, with exceptions for optional \u003ccode\u003eparent\u003c/code\u003e and \u003ccode\u003eheader\u003c/code\u003e fields.\u003c/p\u003e\n"]]],["To create tasks in bulk from a server, use `BatchCreateTasks` via gRPC or REST. Each `CreateTasksRequest` within the `requests` array requires the same validation as a single `CreateTask` request. For example, create pickup and delivery tasks by defining task details like type, state, tracking ID, planned location, and duration. In gRPC, build `CreateTaskRequest` for each task, then a `BatchCreateTasksRequest` including an array of these requests. REST requires a POST request to `BatchCreateTasks` with a JSON payload of `BatchCreateTasksRequest`.\n"],null,["This document shows how to create a batch of tasks from a server environment\nusing gRPC or REST. For more details on creating tasks, see:\n\n- [Create shipment tasks](/maps/documentation/mobility/fleet-engine/journeys/tasks/create-shipment-tasks)\n- [Create other task types](/maps/documentation/mobility/fleet-engine/journeys/tasks/create-other-tasks)\n\nTask fields for creating tasks in batch\n\nWhen creating tasks in batch, each `CreateTasksRequest` element in `requests`\nmust pass the same validation rules as a `CreateTask` request for a single task,\nwith the exception that the `parent` and `header` fields are optional.\nIf set, they must be identical to their respective fields at the top level\n`BatchCreateTasksRequest`.\n\nFor more information, see the API Reference documentation for `BatchCreateTasks`\nfor [gRPC](/maps/documentation/mobility/fleet-engine/reference/tasks/rpc/maps.fleetengine.delivery.v1#maps.fleetengine.delivery.v1.DeliveryService) or [REST](/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/providers.tasks/batchCreate).\n\nRequired batch fields\n\n| Field | Value |\n|----------|-----------------------------|\n| requests | `Array\u003cCreateTasksRequest\u003e` |\n\nOptional batch task fields\n\n| Field | Value |\n|--------|-------------------------|\n| header | `DeliveryRequestHeader` |\n\nCreate a batch of tasks\n\nThe following examples shows how to create both a pickup and a delivery task\nusing the [Java gRPC library](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-tasks#java) or how to make an HTTP REST request to\n[`BatchCreateTask`](/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/providers.tasks/batchCreate). See\n[JWT elements](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/jwt#jwt-elements)\nfor the correct JWT syntax. \n\ngRPC \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Delivery Task settings\n Task deliveryTask = Task.newBuilder()\n .setType(Task.Type.DELIVERY)\n .setState(Task.State.OPEN)\n .setTrackingId(\"delivery-tracking-id\")\n .setPlannedLocation( // Grand Indonesia East Mall\n LocationInfo.newBuilder().setPoint(\n LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))\n .setTaskDuration(\n Duration.newBuilder().setSeconds(2 * 60))\n .build();\n\n // Delivery Task request\n CreateTaskRequest createDeliveryTaskRequest =\n CreateTaskRequest.newBuilder() // No need for the header or parent fields\n .setTaskId(\"task-8312508\") // Task ID assigned by the Provider\n .setTask(deliveryTask) // Initial state\n .build();\n\n // Pickup Task settings\n Task pickupTask = Task.newBuilder()\n .setType(Task.Type.PICKUP)\n .setState(Task.State.OPEN)\n .setTrackingId(\"pickup-tracking-id\")\n .setPlannedLocation( // Grand Indonesia East Mall\n LocationInfo.newBuilder().setPoint(\n LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))\n .setTaskDuration(\n Duration.newBuilder().setSeconds(2 * 60))\n .build();\n\n // Pickup Task request\n CreateTaskRequest createPickupTaskRequest =\n CreateTaskRequest.newBuilder() // No need for the header or parent fields\n .setTaskId(\"task-8241890\") // Task ID assigned by the Provider\n .setTask(pickupTask) // Initial state\n .build();\n\n // Batch Create Tasks settings\n String parent = \"providers/\" + PROJECT_ID;\n\n // Batch Create Tasks request\n BatchCreateTasksRequest batchCreateTasksRequest =\n BatchCreateTasksRequest.newBuilder()\n .setParent(parent)\n .addRequests(createDeliveryTaskRequest)\n .addRequests(createPickupTaskRequest)\n .build();\n\n // Error handling\n // If Fleet Engine does not have any task(s) with these task ID(s) and the\n // credentials of the requestor pass, the service creates the task(s)\n // successfully.\n\n try {\n BatchCreateTasksResponse createdTasks = deliveryService.batchCreateTasks(\n batchCreateTasksRequest);\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 delivery and a pickup task from a server environment, make an\nHTTP REST call to `BatchCreateTasks`: \n\n POST https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/batchCreate\n\n*\\\u003cid\\\u003e* is a unique identifier for the task.\n\nThe request header must contain a field *Authorization* with the value\n*Bearer \\\u003ctoken\\\u003e* , where *\\\u003ctoken\\\u003e* is issued by your server\naccording to the guidelines described in [Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts) and\n[JSON Web tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/jwt).\n\nThe request body must contain a `BatchCreateTasksRequest` entity.\n\nExample `curl` command: \n\n # Set $JWT, $PROJECT_ID, $DELIVERY_TRACKING_ID, $DELIVERY_TASK_ID,\n # $PICKUP_TRACKING_ID, and $PICKUP_TASK_ID in the local environment\n curl -X POST \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks:batchCreate\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"requests\" : [\n {\n \"taskId\": \"${DELIVERY_TASK_ID}\",\n \"task\" : {\n \"type\": \"DELIVERY\",\n \"state\": \"OPEN\",\n \"trackingId\": \"${DELIVERY_TRACKING_ID}\",\n \"plannedLocation\": {\n \"point\": {\n \"latitude\": -6.195139,\n \"longitude\": 106.820826\n }\n },\n \"taskDuration\": \"90s\"\n }\n },\n {\n \"taskId\": \"${PICKUP_TASK_ID}\",\n \"task\" : {\n \"type\": \"PICKUP\",\n \"state\": \"OPEN\",\n \"trackingId\": \"${PICKUP_TRACKING_ID}\",\n \"plannedLocation\": {\n \"point\": {\n \"latitude\": -6.195139,\n \"longitude\": 106.820826\n }\n },\n \"taskDuration\": \"90s\"\n }\n }\n ]\n }\n EOM\n\n| **Experimental:** As an experimental feature, the `LocationInfo` ([gRPC](/maps/documentation/mobility/fleet-engine/reference/tasks/rpc/maps.fleetengine.delivery.v1#locationinfo) or [REST](/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/LocationInfo)) field now supports using `place` ([gRPC](/maps/documentation/mobility/fleet-engine/reference/tasks/rpc/maps.fleetengine.delivery.v1#maps.fleetengine.delivery.v1.LocationInfo.FIELDS.string.maps.fleetengine.delivery.v1.LocationInfo.place) or [REST](/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/LocationInfo#FIELDS.place)), either alongside or instead of `LatLng`.\n\nWhat's next\n\n- [Configure tasks](/maps/documentation/mobility/fleet-engine/journeys/tasks/configure-tasks)\n- [Update tasks](/maps/documentation/mobility/fleet-engine/journeys/tasks/update-tasks)"]]