Errror accessing UserTaskList

Hello,

I get the following exception

{message: “Not Found”, stack: “Error: Not Found
at NotFound.AsanaError (c:\ba…”, status: 404, value: Object}

with the following code.
I am able to get details of myself but not the UserTaskList.
Any help would be appreciated?


var asana = require(‘asana’);

async function Asana() {
var personalAccessToken = ‘…’;
var client = asana.Client.create().useAccessToken(personalAccessToken);
let me = await client.users.me()
let utl = client.userTaskLists
let mytasks = utl.getUserTaskList(me.gid)
try {
mytasks = await mytasks
console.log(JSON.stringify(mytasks,null,’ '))
}catch(ex){
console.log(ex)
}
}
Asana()

Hi @Phil_Tomlinson and welcome to the forum!

Is this using one of the official client libraries; if so, which one?

(You might want to try the operation in Postman or equivalent to make sure the underlying operation is working as you expect.)

Its the latest asana library: “dependencies”: {
“asana”: “^0.18.4”
}

I am hoping that using the client api abstracts the communication from me.

Sorry, I meant the library for which language? I believe it’s Javascript, not 100% sure…

In any case, the underlying issue is as follows: a user’s User Task List (UTL) is actually a separate object, with its own distinct gid that’s different from the user’s gid. So getting a UTL is a two-step process.

Again I’m not sure about the specific library but in terms of the underlying API calls, the first step is to take the user’s gid and call /users/{user_gid}/user_task_list; that will return you the gid of the user’s UTL. (See the API documentation here.)

Then step two is to take that UTL gid and call /user_task_lists/{user_task_list_gid}; that will return you the actual UTL contents. (See the API documentation here.)

Hi Phil, While your answer is correct from the REST perspective, I am attempting to resolve this using the javascript API provided. Using your response I found I can do the following successfully.


var asana = require(‘asana’);

async function Asana() {

try {

// replace with your personal access token. 

var personalAccessToken = '1/1174848714091436:364aea438470d4a9a56f7def57d50c64';

// Construct an Asana client

var client = asana.Client.create().useAccessToken(personalAccessToken);

let userClient = client.users

let me = await client.users.me()

let workspace = me.workspaces[0].gid

let userTaskList = await client.userTaskLists.findByUser(me.gid, {workspace})

let tasks = await client.tasks.findByUserTaskList(userTaskList.gid)



tasks.data.forEach(t=>{

    console.log(t.name)

})



}catch(ex){

    console.log(ex)

}

}

Asana()

Thanks, Phil

1 Like

I’ve deauthorized the PAT there.