Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En este documento, se muestra cómo crear un lote de tareas desde un entorno de servidor con gRPC o REST. Para obtener más información sobre cómo crear tareas, consulta los siguientes recursos:
Cuando se crean tareas por lotes, cada elemento CreateTasksRequest en requests debe pasar las mismas reglas de validación que una solicitud CreateTask para una sola tarea, con la excepción de que los campos parent y header son opcionales.
Si se configuran, deben ser idénticos a sus respectivos campos en el nivel superior BatchCreateTasksRequest.
Para obtener más información, consulta la documentación de referencia de la API de BatchCreateTasks para gRPC o REST.
Campos obligatorios del lote
Campo
Valor
solicitudes
Array<CreateTasksRequest>
Campos de tareas por lotes opcionales
Campo
Valor
encabezado
DeliveryRequestHeader
Crea un lote de tareas
En los siguientes ejemplos, se muestra cómo crear una tarea de retiro y una de entrega con la biblioteca de gRPC de Java o cómo realizar una solicitud de REST HTTP a BatchCreateTask. Consulta los elementos JWT para conocer la sintaxis correcta de 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
Para crear una tarea de entrega y una de retiro desde un entorno de servidor, realiza una llamada REST HTTP a BatchCreateTasks:
El encabezado de la solicitud debe contener un campo Authorization con el valor Bearer <token>, donde <token> lo emite tu servidor según los lineamientos que se describen en Roles de la cuenta de servicio y Tokens web JSON.
El cuerpo de la solicitud debe contener una entidad BatchCreateTasksRequest.
Comando curl de ejemplo
# 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
[null,null,["Última actualización: 2025-08-31 (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)"]]