API call to duplicate task does not actually duplicate task

I’m trying to write a simple API call to duplicate a task. I’m hitting the following endpoint:

https://app.asana.com/api/1.0/tasks/1234/duplicate

Here is my request body:

{
“data”: {
“name”: “duplicate task”,
“projects”: “5678”
}
}

Here is the response from my call:

{
“data”: {
“gid”: “6666”,
“resource_type”: “job”,
“resource_subtype”: “duplicate_task”,
“status”: “in_progress”,
“new_task”: {
“gid”: “7777”,
“resource_type”: “task”,
“name”: “duplicate task”,
“resource_subtype”: “default_task”
}
}
}

The way I understand it is that the “gid” returned is the id of a job that is supposed to run to complete the duplication of the task. I hit the endpoint to check the job and it tells me that it completed successfully, but when I check Asana the “duplicate task” is nowhere to be found. Am I doing something wrong? If so, any help will be much appreciated.

Hi @Brendon_Davies,

In the response you pasted, I see that the new_task field points to a task in Asana. Are you able to fetch that task via GET /tasks/<task-gid>? Inspecting that task will tell you where it is.

@Joe_Trollo Yeah, sorry I didn’t post that with my original question. Here’s the response from hitting the tasks endpoint with that task “gid”:

{
“data”: {
“id”: 91011,
“gid”: “91011”,
“assignee”: null,
“assignee_status”: “upcoming”,
“completed”: false,
“completed_at”: null,
“created_at”: “2019-10-10T19:36:32.110Z”,
“due_at”: null,
“due_on”: null,
“collaborators”: [
{
“id”: 5678,
“gid”: “5678”,
“name”: “Brendon Davies”,
“resource_type”: “user”
}
],
“hearted”: false,
“hearts”: ,
“liked”: false,
“likes”: ,
“memberships”: ,
“modified_at”: “2019-10-10T19:36:32.110Z”,
“name”: “duplicate task”,
“notes”: “”,
“num_hearts”: 0,
“num_likes”: 0,
“parent”: null,
“projects”: ,
“resource_type”: “task”,
“start_on”: null,
“tags”: ,
“resource_subtype”: “default_task”,
“workspace”: {
“id”: 1234,
“gid”: “1234”,
“name”: “the-infiniteloop.com”,
“resource_type”: “workspace”
}
}
}

I see that the value returned for “projects” is an empty array, that’s why I added that to my request but still it doesn’t get added to my project.

Hi @Brendon_Davies—the task duplication endpoint does not accept a projects parameter. You can consult the documentation for the parameters it does accept. I believe you want to specify include: ["projects"]

1 Like

@Joe_Trollo that works now, THANK YOU! :grinning:

1 Like

3 posts were split to a new topic: How do I duplicate a task and all sub tasks?