# Google Cloud Tasks V2 Client - Class CreateTaskRequest (2.2.0)

2.2.0 (latest) 2.1.2 2.0.2 1.15.2 1.14.6 1.13.2 1.12.2 1.11.11 Reference documentation and code samples for the Google Cloud Tasks V2 Client class CreateTaskRequest.

Request message for
[CreateTask](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__createTask__).

Generated from protobuf message `google.cloud.tasks.v2.CreateTaskRequest`

## Namespace

Google \\ Cloud \\ Tasks \\ V2

## Methods

### __construct

Constructor.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `data` | `array` Optional. Data for populating the Message object. |
| `↳ parent` | `string` Required. The queue name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` The queue must already exist. |
| `↳ task` | `https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task` 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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). 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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). If [schedule_time](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getScheduleTime__) 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](https://docs.cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Code.html#_Google_Rpc_Code__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task) will be returned. By default response_view is [BASIC](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__FULL) requires `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/) permission on the [Task](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). 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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__).
If [schedule_time](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getScheduleTime__) 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](https://docs.cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Code.html#_Google_Rpc_Code__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task|null` |   |

### hasTask

### clearTask

### setTask

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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). 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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__).
If [schedule_time](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getScheduleTime__) 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](https://docs.cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Code.html#_Google_Rpc_Code__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getResponseView

The response_view specifies which subset of the
[Task](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task) will be returned.

By default response_view is [BASIC](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__FULL) requires
`cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
permission on the [Task](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task) resource.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` | Enum of type [View](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View). |

### setResponseView

The response_view specifies which subset of the
[Task](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task) will be returned.

By default response_view is [BASIC](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View#_Google_Cloud_Tasks_V2_Task_View__FULL) requires
`cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
permission on the [Task](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task) resource.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `int` Enum of type [View](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task.View). |

| **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` | `https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task` 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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). 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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getName__). If [schedule_time](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Task#_Google_Cloud_Tasks_V2_Task__getScheduleTime__) 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](https://docs.cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Code.html#_Google_Rpc_Code__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](https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.Client.CloudTasksClient#_Google_Cloud_Tasks_V2_Client_CloudTasksClient__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. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-tasks/latest/V2.CreateTaskRequest` |   |