Required. The task to add. Task names have the following format: projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID. The user can optionally specify a task name. If a name is not specified then the system will generate a random unique task id, which will be set in the task returned in the response. If schedule_time is not set or is in the past then Cloud Tasks will set it to the current time. Task De-duplication: Explicitly specifying a task ID enables task de-duplication. If a task's ID is identical to that of an existing task or a task that was deleted or executed recently then the call will fail with ALREADY_EXISTS. If the task's queue was created using Cloud Tasks, then another task with the same name can't be created for ~1hour after the original task was deleted or executed. If the task's queue was created using queue.yaml or queue.xml, then another task with the same name can't be created for ~9days after the original task was deleted or executed. Because there is an extra lookup cost to identify duplicate task names, these CreateTask calls have significantly increased latency. Using hashed strings for the task id or for the prefix of the task id is recommended. Choosing task ids that are sequential or have sequential prefixes, for example using a timestamp, causes an increase in latency and error rates in all task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently.
↳ response_view
int
The response_view specifies which subset of the Task will be returned. By default response_view is BASIC; not all information is retrieved by default because some data, such as payloads, might be desirable to return only when needed because of its large size or because of the sensitivity of data that it contains. Authorization for FULL requires cloudtasks.tasks.fullViewGoogle IAM permission on the Task resource.
getParent
Required. The queue name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID
The queue must already exist.
Returns
Type
Description
string
setParent
Required. The queue name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID
The queue must already exist.
Parameter
Name
Description
var
string
Returns
Type
Description
$this
getTask
Required. The task to add.
Task names have the following format:
projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID.
The user can optionally specify a task
name. If a name is not specified then
the system will generate a random unique task id, which will be set in the
task returned in the response.
If schedule_time is not set or
is in the past then Cloud Tasks will set it to the current time.
Task De-duplication:
Explicitly specifying a task ID enables task de-duplication. If
a task's ID is identical to that of an existing task or a task
that was deleted or executed recently then the call will fail
with ALREADY_EXISTS.
If the task's queue was created using Cloud Tasks, then another task with
the same name can't be created for ~1hour after the original task was
deleted or executed. If the task's queue was created using queue.yaml or
queue.xml, then another task with the same name can't be created
for ~9days after the original task was deleted or executed.
Because there is an extra lookup cost to identify duplicate task
names, these CreateTask
calls have significantly increased latency. Using hashed strings for the
task id or for the prefix of the task id is recommended. Choosing task ids
that are sequential or have sequential prefixes, for example using a
timestamp, causes an increase in latency and error rates in all
task commands. The infrastructure relies on an approximately
uniform distribution of task ids to store and serve tasks
efficiently.
Task names have the following format:
projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID.
The user can optionally specify a task
name. If a name is not specified then
the system will generate a random unique task id, which will be set in the
task returned in the response.
If schedule_time is not set or
is in the past then Cloud Tasks will set it to the current time.
Task De-duplication:
Explicitly specifying a task ID enables task de-duplication. If
a task's ID is identical to that of an existing task or a task
that was deleted or executed recently then the call will fail
with ALREADY_EXISTS.
If the task's queue was created using Cloud Tasks, then another task with
the same name can't be created for ~1hour after the original task was
deleted or executed. If the task's queue was created using queue.yaml or
queue.xml, then another task with the same name can't be created
for ~9days after the original task was deleted or executed.
Because there is an extra lookup cost to identify duplicate task
names, these CreateTask
calls have significantly increased latency. Using hashed strings for the
task id or for the prefix of the task id is recommended. Choosing task ids
that are sequential or have sequential prefixes, for example using a
timestamp, causes an increase in latency and error rates in all
task commands. The infrastructure relies on an approximately
uniform distribution of task ids to store and serve tasks
efficiently.
The response_view specifies which subset of the
Task will be returned.
By default response_view is BASIC;
not all information is retrieved by default because some data, such as
payloads, might be desirable to return only when needed because
of its large size or because of the sensitivity of data that it
contains.
Authorization for FULL requires
cloudtasks.tasks.fullViewGoogle IAM
permission on the Task resource.
Returns
Type
Description
int
setResponseView
The response_view specifies which subset of the
Task will be returned.
By default response_view is BASIC;
not all information is retrieved by default because some data, such as
payloads, might be desirable to return only when needed because
of its large size or because of the sensitivity of data that it
contains.
Authorization for FULL requires
cloudtasks.tasks.fullViewGoogle IAM
permission on the Task resource.
Parameter
Name
Description
var
int
Returns
Type
Description
$this
static::build
Parameters
Name
Description
parent
string
Required. The queue name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID
The queue must already exist. Please see
CloudTasksClient::queueName() for help formatting this field.
Task names have the following format:
projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID.
The user can optionally specify a task
name. If a name is not specified then
the system will generate a random unique task id, which will be set in the
task returned in the response.
If schedule_time is not set or
is in the past then Cloud Tasks will set it to the current time.
Task De-duplication:
Explicitly specifying a task ID enables task de-duplication. If
a task's ID is identical to that of an existing task or a task
that was deleted or executed recently then the call will fail
with ALREADY_EXISTS.
If the task's queue was created using Cloud Tasks, then another task with
the same name can't be created for ~1hour after the original task was
deleted or executed. If the task's queue was created using queue.yaml or
queue.xml, then another task with the same name can't be created
for ~9days after the original task was deleted or executed.
Because there is an extra lookup cost to identify duplicate task
names, these CreateTask
calls have significantly increased latency. Using hashed strings for the
task id or for the prefix of the task id is recommended. Choosing task ids
that are sequential or have sequential prefixes, for example using a
timestamp, causes an increase in latency and error rates in all
task commands. The infrastructure relies on an approximately
uniform distribution of task ids to store and serve tasks
efficiently.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Google Cloud Tasks V2 Client - Class CreateTaskRequest (2.0.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.2 (latest)](/php/docs/reference/cloud-tasks/latest/V2.CreateTaskRequest)\n- [2.0.1](/php/docs/reference/cloud-tasks/2.0.1/V2.CreateTaskRequest)\n- [1.15.2](/php/docs/reference/cloud-tasks/1.15.2/V2.CreateTaskRequest)\n- [1.14.6](/php/docs/reference/cloud-tasks/1.14.6/V2.CreateTaskRequest)\n- [1.13.2](/php/docs/reference/cloud-tasks/1.13.2/V2.CreateTaskRequest)\n- [1.12.2](/php/docs/reference/cloud-tasks/1.12.2/V2.CreateTaskRequest)\n- [1.11.11](/php/docs/reference/cloud-tasks/1.11.11/V2.CreateTaskRequest) \nReference documentation and code samples for the Google Cloud Tasks V2 Client class CreateTaskRequest.\n\nRequest message for\n[CreateTask](/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__createTask__).\n\nGenerated from protobuf message `google.cloud.tasks.v2.CreateTaskRequest`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Tasks \\\\ V2\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getParent\n\nRequired. The queue name. For example:\n`projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`\nThe queue must already exist.\n\n### setParent\n\nRequired. The queue name. For example:\n`projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`\nThe queue must already exist.\n\n### getTask\n\nRequired. The task to add.\n\nTask names have the following format:\n`projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`.\nThe user can optionally specify a task\n[name](/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). If a name is not specified then\nthe system will generate a random unique task id, which will be set in the\ntask returned in the [response](/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__).\nIf [schedule_time](/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getScheduleTime__) is not set or\nis in the past then Cloud Tasks will set it to the current time.\nTask De-duplication:\nExplicitly specifying a task ID enables task de-duplication. If\na task's ID is identical to that of an existing task or a task\nthat was deleted or executed recently then the call will fail\nwith [ALREADY_EXISTS](https://cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Code.html#_Google_Rpc_Code__ALREADY_EXISTS).\nIf the task's queue was created using Cloud Tasks, then another task with\nthe same name can't be created for \\~1hour after the original task was\ndeleted or executed. If the task's queue was created using queue.yaml or\nqueue.xml, then another task with the same name can't be created\nfor \\~9days after the original task was deleted or executed.\nBecause there is an extra lookup cost to identify duplicate task\nnames, these [CreateTask](/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__createTask__)\ncalls have significantly increased latency. Using hashed strings for the\ntask id or for the prefix of the task id is recommended. Choosing task ids\nthat are sequential or have sequential prefixes, for example using a\ntimestamp, causes an increase in latency and error rates in all\ntask commands. The infrastructure relies on an approximately\nuniform distribution of task ids to store and serve tasks\nefficiently.\n\n### hasTask\n\n### clearTask\n\n### setTask\n\nRequired. The task to add.\n\nTask names have the following format:\n`projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`.\nThe user can optionally specify a task\n[name](/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). If a name is not specified then\nthe system will generate a random unique task id, which will be set in the\ntask returned in the [response](/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__).\nIf [schedule_time](/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getScheduleTime__) is not set or\nis in the past then Cloud Tasks will set it to the current time.\nTask De-duplication:\nExplicitly specifying a task ID enables task de-duplication. If\na task's ID is identical to that of an existing task or a task\nthat was deleted or executed recently then the call will fail\nwith [ALREADY_EXISTS](https://cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Code.html#_Google_Rpc_Code__ALREADY_EXISTS).\nIf the task's queue was created using Cloud Tasks, then another task with\nthe same name can't be created for \\~1hour after the original task was\ndeleted or executed. If the task's queue was created using queue.yaml or\nqueue.xml, then another task with the same name can't be created\nfor \\~9days after the original task was deleted or executed.\nBecause there is an extra lookup cost to identify duplicate task\nnames, these [CreateTask](/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__createTask__)\ncalls have significantly increased latency. Using hashed strings for the\ntask id or for the prefix of the task id is recommended. Choosing task ids\nthat are sequential or have sequential prefixes, for example using a\ntimestamp, causes an increase in latency and error rates in all\ntask commands. The infrastructure relies on an approximately\nuniform distribution of task ids to store and serve tasks\nefficiently.\n\n### getResponseView\n\nThe response_view specifies which subset of the\n[Task](/php/docs/reference/cloud-tasks/latest/V2.Task) will be returned.\n\nBy default response_view is [BASIC](/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__BASIC);\nnot all information is retrieved by default because some data, such as\npayloads, might be desirable to return only when needed because\nof its large size or because of the sensitivity of data that it\ncontains.\nAuthorization for [FULL](/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__FULL) requires\n`cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)\npermission on the [Task](/php/docs/reference/cloud-tasks/latest/V2.Task) resource.\n\n### setResponseView\n\nThe response_view specifies which subset of the\n[Task](/php/docs/reference/cloud-tasks/latest/V2.Task) will be returned.\n\nBy default response_view is [BASIC](/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__BASIC);\nnot all information is retrieved by default because some data, such as\npayloads, might be desirable to return only when needed because\nof its large size or because of the sensitivity of data that it\ncontains.\nAuthorization for [FULL](/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__FULL) requires\n`cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)\npermission on the [Task](/php/docs/reference/cloud-tasks/latest/V2.Task) resource.\n\n### static::build"]]