I want to add task in my project but i am unable to add Node.js

const PERSONAL_ACCESS_TOKEN = ‘0/36de6f5822aabe63a01b5136dxxxxx’
const WORKSPACE_ID = 114550371858xxxx

const asana = require(‘asana’);

const client = asana.Client.create({“defaultHeaders”: {“asana-enable”: “string_ids,new_sections”}}).useAccessToken(PERSONAL_ACCESS_TOKEN);

const newTask = { name: “Your Mission” };

try {
client.tasks.createInWorkspace(WORKSPACE_ID, newTask)
.then(response => console.log(response))
} catch (error) {
console.log(error.value)
}

My console result is bellow.
{ gid: ‘114557283885XXXX’,
resource_type: ‘task’,
created_at: ‘2019-10-18T13:31:15.892Z’,
modified_at: ‘2019-10-18T13:31:15.892Z’,
name: ‘Your Mission’,
resource_subtype: ‘default_task’,
notes: ‘’,
assignee: null,
completed: false,
assignee_status: ‘upcoming’,
completed_at: null,
due_on: null,
due_at: null,
projects: ,
start_on: null,
memberships: ,
tags: ,
workspace:
{ gid: ‘114550371858XXXX’,
resource_type: ‘workspace’,
name: ‘Demo Project 1’ },
num_hearts: 0,
num_likes: 0,
parent: null,
hearted: false,
hearts: ,
collaborators:
[ { gid: ‘18819586361XXXX’,
resource_type: ‘user’,
name: ‘Rahul Prajapati’ } ],
liked: false,
likes: }

Please help me. … Thanks In Advance.

Hi @Rahul_Prajapati and welcome to the forum!

From the output you posted, it looks like it successfully created a task. What’s your specific question or issue?

Hi its a issue . If as per the output task is created . then why not i can see added task on my asana portal.

Where are you looking for it? It hasn’t been assigned to a project and it’s not assigned to you, so the only place you’d find it is via Search.

1 Like

Thanks Phil_Seeman Its working now. But will you please help me how to assign task to other person using node.js

You’ll need to find the User ID of that desired person (Users calls are here) and then in your create call, set assignee: "114xxxxxxxxxx158" where the “114xxxxxxxxxx158” is the desired user’s ID.

1 Like

Thank you.

HI @Phil_Seeman I want to create sub tasks while creating a task but its not create. Its create another task…
I use bellow API
https://app.asana.com/api/1.0/tasks/56457833293282/subtasks?

Request Body-
{
“data”: {
“name”: “Sub Task 1”,
“assignee”: {
“id”: 1145676348955XXX,
“gid”: “1145676348955816”,
“resource_type”: “user”,
“name”: “Rohit XXX”
},
“completed”: false,
“due_on”: “2019-11-26”,
“external”: {
“gid”: “56457833293XXX”,
“data”: “Task 1.”
},
“html_notes”: “ call him and request for document”,
“notes”: “Call timing 11:00 AM to 6:00 PM”,
“projects”: [
“1145669477494XXX”
],
“workspace”: “1145545202934XXX”
}
}

Are you sure it’s not creating a subtask?

You’ve specified a project, which means that in addition to creating a subtask it’s going to assign that subtask to the specified project. Assigning it to the project will cause it to appear in the main tasks list for the project (that’s just the way the Asana UI works) so even though it’s a subtask, you might be thinking it’s a task because you see it in the project’s tasks list?

1 Like

I have solved . but may i assign a task to multiple assignee?

No, you can only assign a task to one user. This is a limitation of Asana which is a design decision on their part; you can read about that decision here:

If you want to register your vote that you’d like to have that changed, you can do so here: