Duplicating task PHP

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

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)

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

Any help is greatly apprieciated!

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.

1 Like

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.

1 Like

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

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

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

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

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

            'include' => ['name'],

        ]);

Does not work either

Ive tried more ways…

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

//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();
    }
[
     '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)

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… :sweat_smile:

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

  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!

1 Like

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.

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

1 Like

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

1 Like

Thank you for replying anyway :slight_smile:

1 Like