0

I'm trying to create a task and then set a project on the task using nodejs and the asana thin wrapper available from npm.

var asana = require('asana');
var newTask = { name: "Your Mission", notes: "Stuff" };
var project = [{ id:321, name: "Missions Impossible"}];

var client = asana.Client.basicAuth('APIKEY');

client.tasks.createInWorkspace(123, newTask).then(function(task) {

    client.tasks.addProject(task.id, project).then(function(o) {

        // Check for empty object returned (sign of success)

        if (Object.keys(o).length === 0)
            console.log('yay!');
        else
            console.log('booo');
}

The task is created, but I get an error in the addProject method - "Possibly unhandled error. Invalid Request". I've tried different variations on the project object, but I'm out of ideas.

Is the project wrongly formed? Something else?

Jim N
  • 28
  • 4

1 Answers1

2

You are right, your project is malformed. The data passed to the addProject method should be a dictionary with the member:

project: 321

or

project: { id: 321 }

See the documentation for the endpoint being called and the data that it gets passed.

Greg S
  • 2,079
  • 1
  • 11
  • 10
  • Your answer is a bit unclear, as JavaScript has no 'dictionary' object, but setting my project = { project: 321 } worked. Setting the project = 321 does NOT work. The Asana documentation is nice, but it's rather ambiguous. Thanks for the answer, tho, finally working! – Jim N Dec 12 '14 at 16:14