# Duplicating task PHP

**URL:** <https://forum.asana.com/t/duplicating-task-php/207049>\
**Category:** API & Developers\
**Created:** [30 September 2022 14:16 UTC](https://forum.asana.com/t/duplicating-task-php/207049 "2022-09-30T14:16:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![JordyK](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jordyk/32/115041_2.png) [@JordyK](https://forum.asana.com/u/JordyK)\
**Post date:** [30 September 2022 14:16 UTC](https://forum.asana.com/t/duplicating-task-php/207049/1 "2022-09-30T14:16:34Z")

</div>

Hi, I am fairly new to using the API. I am using PHP… Trying out how the API functions before propperly implementing it.

For what we want to achieve we have to duplicate tasks, I am strugling with the documentation, it tells me that the function excists but does not provide a proper example for the include field.

What is expected to be passed in (what type/ in what form)?  
And may I ask why it is not the same accros the entire api…

$task is already the task-\>gid below

```auto
AsanaController::getClient()->tasks->duplicateTask($task, [
            'include' => 'name'
        ]);

```

This does not work, I have played around… passing multiple values in… Like how [‘headers’ =\> [‘asana-disable’ =\> ‘disabled\_fields’]] works… But this does not work either, I keep getting ‘Invalid request’

Could someone provide me with a proper code example in PHP on how to use this include field?

It is frustating this is not globally the same, since passing in the values like I did above does in fact work for creating and updating tasks (Why not for duplicating it?)

In the documentation does not tell me how the field works… I have provided it an array with the field include… containing a string value(in docs it says it expects a string for the field)

```auto
$result = $client->tasks->duplicateTask($task_gid, array('field' => 'value', 'field' => 'value'), array('opt_pretty' => 'true'))

```

Any help is greatly apprieciated!

---

<div class="post-metadata">

**Author:** ![Frederic\_Malenfant](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/frederic_malenfant/32/8358_2.png) [@Frederic\_Malenfant](https://forum.asana.com/u/Frederic_Malenfant)\
**Post date:** [30 September 2022 15:25 UTC](https://forum.asana.com/t/duplicating-task-php/207049/2 "2022-09-30T15:25:04Z")

</div>

I don’t know much about php…  
but in the documentation (web REST), I see that the ‘include’ parameter should be an array…

So, maybe you can try  
‘include’ =\> array(‘name’)  
instead?

I NEVER look at the code sample of the documentation, I don’t remember having read a sample that really helps.

The “body parameter” section is better for me.

If you have a tool like Fiddler that can track the web request that is sent/received from your php, that should help.

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [30 September 2022 22:11 UTC](https://forum.asana.com/t/duplicating-task-php/207049/3 "2022-09-30T22:11:26Z")

</div>

Hi @JordyK,

I don’t know PHP, but `include` should be sent as an array, where the array elements are the fields you want duplicated, such as `notes`, `assignee`, etc.

---

<div class="post-metadata">

**Author:** ![JordyK](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jordyk/32/115041_2.png) [@JordyK](https://forum.asana.com/u/JordyK)\
**Post date:** [3 October 2022 06:48 UTC](https://forum.asana.com/t/duplicating-task-php/207049/4 "2022-10-03T06:48:13Z")

</div>

As I am sending it now, include is an array.

> [@JordyK](#):
>
> ```auto
> [
> 'include' => 'name'
> ]
> 
> ```

and name is a string (same as in the example). Just in the docs they use php and thus have to do array(param =\> field) I can simply do [param =\> field]… This is identical

---

<div class="post-metadata">

**Author:** ![JordyK](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jordyk/32/115041_2.png) [@JordyK](https://forum.asana.com/u/JordyK)\
**Post date:** [3 October 2022 06:48 UTC](https://forum.asana.com/t/duplicating-task-php/207049/5 "2022-10-03T06:48:42Z")

</div>

(Not sure if this is just new in php or a Laravel feature

---

<div class="post-metadata">

**Author:** ![JordyK](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jordyk/32/115041_2.png) [@JordyK](https://forum.asana.com/u/JordyK)\
**Post date:** [3 October 2022 06:52 UTC](https://forum.asana.com/t/duplicating-task-php/207049/6 "2022-10-03T06:52:36Z")

</div>

I tried this too… And again just now to make sure.

```auto
  AsanaController::getClient()->tasks->duplicateTask($task, [

            'include' => ['name'],

        ]);

```

Does not work either

---

<div class="post-metadata">

**Author:** ![JordyK](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jordyk/32/115041_2.png) [@JordyK](https://forum.asana.com/u/JordyK)\
**Post date:** [3 October 2022 07:19 UTC](https://forum.asana.com/t/duplicating-task-php/207049/7 "2022-10-03T07:19:42Z")

</div>

Ive tried more ways…

Original request here, in the examples I will just show the include array

```auto
//Does not work (invalid request, just like everything I try)
 public function duplicate($project, $task)
    {
        AsanaController::getClient()->tasks->duplicateTask($task, ['include' => 'name']);
        return redirect()->back();
    }

```

```auto
[
     'include' => ['projects', 'name'],
 ]
-------------------
array('include' => array('projects', 'name'))
 //These two should be equal anyway ^

//Pass as one long string
[
 'include' => 'projects, name, notes, resource_subtype, completed',
]

//Pass as long string inside another array
 [
  'include' => ['projects, name, notes, resource_subtype, completed'],
 ]

```

Every single one returns ‘Invalid request’. To eliminate it is the way I process this I have rewritten it so it would update the task to completed in the exact same function (just temp replaced it)

```auto
public function duplicate($project, $task)
    {
        AsanaController::getClient()->tasks->updateTask($task, ['completed' => true]);
        return redirect()->back();
    }

```

This works fine. But i just want to duplicate it…

I see you post alot here Phil. Happen to know someone that does know PHP that might be able to help me. Just one code example would be enough… 😅

---

<div class="post-metadata">

**Author:** ![JordyK](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jordyk/32/115041_2.png) [@JordyK](https://forum.asana.com/u/JordyK)\
**Post date:** [3 October 2022 08:03 UTC](https://forum.asana.com/t/duplicating-task-php/207049/8 "2022-10-03T08:03:01Z")

</div>

After some wrestling and asking. Passing in a name is required… Atleast, It works when I do pass one in.

```auto
  public function duplicate($project, $task)
    {
        AsanaController::getClient()->tasks->duplicateTask(
            $task,
            [
                'name' => 'Test 123',
                'include' => [
                    'notes',
                    'assignee',
                    'subtasks',
                    'attachments',
                    'tags',
                    'followers',
                    'projects',
                    'dates',
                    'parent',
                ],
            ]
        );
        return redirect()->back();
    }

```

This works. Thank you for trying to help!

---

<div class="post-metadata">

**Author:** ![Shane8](https://luna1.co/8d76cd.png) [@Shane8](https://forum.asana.com/u/Shane8)\
**Post date:** [3 October 2022 08:13 UTC](https://forum.asana.com/t/duplicating-task-php/207049/9 "2022-10-03T08:13:18Z")

</div>

I have been testing this my self and found out there are 2 required parameters one in includes, which is ‘projects’ and then name or it wont work as the below example works.

```auto
require 'vendor/autoload.php';

$client = Asana\Client::accessToken('ENTER ACCESS TOKEN', 
    array('headers' => array('asana-enable' => 'new_user_task_lists')));
	
$task_gid = 'ENTER TASK ID';

$duplicate_task = array(

		'include' => [
			'projects'
		],
		'name' => 'New test task 1',
		
	);

$result = $client->tasks->duplicateTask($task_gid, $duplicate_task, array('opt_pretty' => 'true'));

```

This should be included in the documentation as required but unfortunately its not

---

<div class="post-metadata">

**Author:** ![Shane8](https://luna1.co/8d76cd.png) [@Shane8](https://forum.asana.com/u/Shane8)\
**Post date:** [3 October 2022 08:15 UTC](https://forum.asana.com/t/duplicating-task-php/207049/10 "2022-10-03T08:15:44Z")

</div>

Apologies as I was testing this out during my reply and did not see you found the solution your self. But as stated ‘projects’ parameter in includes and the name parameter that is required other than that you can use any other parameters you require

---

<div class="post-metadata">

**Author:** ![JordyK](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jordyk/32/115041_2.png) [@JordyK](https://forum.asana.com/u/JordyK)\
**Post date:** [3 October 2022 11:21 UTC](https://forum.asana.com/t/duplicating-task-php/207049/11 "2022-10-03T11:21:20Z")

</div>

Thank you for replying anyway 🙂

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 18:56 UTC](https://forum.asana.com/t/duplicating-task-php/207049/12 "2025-05-30T18:56:28Z")

</div>

Closed on 30 May 2025 18:56 UTC


