3

I am trying to use the Asana API to create a task that is assigned to me and added to an existing project.

I have tried by not specifying the workspace as suggested by someone else but the task creation still fails.

The jSon I am using is the following;

{ "data": 
{
"name":"Testing Project",
"followers":[10112, 141516],
"workspace":6789,
"assignee":12345,
"project": 1234
}
}

If I create the task and then send another call to the API with the following jSon it works, but this means I need to make 2 API calls every time I create a task.

{
"project": 1234
}
Adam Lear
  • 38,111
  • 12
  • 81
  • 101
bwhouse
  • 31
  • 2

3 Answers3

3

Rather old question but it might help someone. Yes, you can attach a task to a project during creation using the 'projects' (not 'project' as stated above) param, passing its id.

You can also attach the task to many projects stating an array at 'projects' => {22, 33, 44}.

It's all here at https://asana.com/developers/api-reference/tasks

Justin
  • 3,418
  • 3
  • 27
  • 37
vortal
  • 139
  • 2
  • 9
2

(I work for Asana)

The specification for Tasks can be found here: https://asana.com/developers/api-reference/tasks Notably, you cannot specify a project during creation - you must go through the addProject call for each project you wish to add.

If there is contradictory information on another SO question, I apologize as that may have been written without first double-checking the implementation.

Justin
  • 3,418
  • 3
  • 27
  • 37
Greg S
  • 2,079
  • 1
  • 11
  • 10
  • Is Asana API able to add a tag to a task? Because it appears that this API does not exist yet. – Roy Lee Jun 22 '12 at 02:20
  • 1
    Yes, that functionality was added very recently. – Greg S Jun 23 '12 at 02:26
  • 2
    Thanks for your answer Greg. It would be nice to be able to associate a project with a task on creation. I imagine this is a common scenario. – Emil Oct 18 '12 at 09:49
  • Yes, it is a common scenario and we'll look into making that easier. – Greg S Oct 20 '12 at 00:04
  • 1
    It would be awsome if you could update the documentation that it isn't possible, otherwise to many people spend to much time due to an mistake in the documentation.. – goemic Jan 10 '18 at 15:17
0

The actual problem is that you are passing an int instead of an string for "projects". Some attributes work well as string or int (e.g. "assignee" or "workspace") but not "projects".

..so correct your json to the following:

{ 
    "data": 
    {
        "name":"Testing Project",
        "followers":[10112, 141516],
        "workspace":6789,
        "assignee":12345,
        "project": "1234"
    }
}

I wasted half a day -.-'

goemic
  • 1,092
  • 12
  • 24