When trying get all tasks for project using recursive function, Asana not returning all tasks

Hello,

We are developing an integration when we need to get all the tasks from a Project.

Sometimes it works, and sometimes it doesnt returns all the tasks.

Here the peice of code:

private async collectTasks( projectGid:string, offsetToken:string = '' ): Promise<void> {
 try {
  const params:any = {
   limit: 100,
   fields: 'name,assignee,assignee.email,due_on'
  }
  if(offsetToken)
   params.offset = offsetToken;
  
  const tasks = await this.createTokenClient().tasks.findByProject(projectGid, params);
  
  this.tasks = this.tasks.concat(tasks.data);
  
  if(
   tasks._response
   &&
   tasks._response.next_page
   &&
   tasks._response.next_page.offset
  ) {
   await this.collectTasks(projectGid, tasks._response.next_page.offset)
  } else {
   this.isAllTasksHere = true;
  }
 } catch (e) {
  console.log('ERROR WHEN GETTING TASKS', e.value);
 }
}

is there any missing command ?Can anyone help please?

Thank you in advance
Lamine

Nothing jumps out at me as an issue. What language is this? Are you using an official Asana client library?

Thank you for your help.

Language: node.js
yes, we are using official asana library

All of the official client libraries implement pagination internally; you shouldn’t have to use any code to do that yourself. The call should return all tasks in the project automatically.

Confirming with @Bastien_Siebman - you use the Node library, right? It handles all pagination itself, yes?

Could you pelase tell me which library? we are using an official library and it is not bringing all tasks.

Looking at the source for the Node library:

It says:

* Get remaining results from a collection request, transparently
* paginating until pages exhausted or until `maxItems` items collected.

Thank you very much for your help.

I’ll try it and let you know.

Yes the node library does have pagination built in using the collection mechanism (everything is described on the Github)

Thank you for your help

This is the library we are using GitHub - Asana/node-asana: Official node.js and browser JS client for the Asana API v1 but unfortunately, it is not bringing all tasks.

Someting looks strange/broken

We have 125 tasks, this library permits to get only a part of them with pagination token.

I’m receiving (not all the the time) this error:

{ Error: getaddrinfo ENOTFOUND app.asana.com app.asana.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'app.asana.com',
  host: 'app.asana.com',
  port: 443 }

We are trying to get all the tasks form a Project Template, then create a project from that template. Sometimes it bring all tasks, and sometimes it shows the above error and it miss some tasks.

Any help please

Hi @lpb @Phil_Seeman @Bastien_Siebman @paulminors

Any insight regarding this case? what could be the problem?

  • a bug
  • a limitation of the API as we hav 125 tasks in the project
  • a missing commande?
  • Other

Your help is really appreciated.

Thanks in advance
Lamine

Sorry, @Lamine_B, I’ll have to defer to the others… Best wishes.

Afraid I’m not of much more help - it looks specific to the Node library which I don’t use. I do know @Bastien_Siebman uses it, though, and I don’t think has had any issues retrieving all tasks?

Can you share your Node code please? Just the loop with the collection. I never had issues like this.

@Lamine_B how is your internet connection? We had DNS and connection problems a while ago and then we had similar errors in nodejs (ENOTFOUND).

Back then we did a quite dirty fix and simply iterated over one task until it was received in full (with a while loop). It worked, but as soon as internet got better, the errors vanished.

@Andre_Lung We don’t have any issue with the Internet at the moment. My developer could resolve the problem.

He told me that Asana limits to 15/min the number of records (tasks in our case) you can pull using API

So he raised the timeout of the script and waited until it pulls all the tasks.

HTH.
Lamine

There is a rate limit but it’s not necessarily 15 per minute; it’s much more complex than that and depends on a number of factors. It’s all explained here:

FYI the correct way to handle Asana rate limits is not just to add a timeout; that may well work but will be less efficient and take longer than necessary. The correct way is explained in the API docs:

To protect the stability of the API and keep it available to all users, Asana enforces multiple kinds of rate limiting. Requests that hit any of our rate limits will receive a 429 Too Many Requests response, which contains the standard Retry-After header indicating how many seconds the client should wait before retrying the request.

As it says, the proper way to handle it is to catch a 429 exception, read the Retry-After header value, and wait that number of seconds.

1 Like

I stumbled upon this thread again. I have the “Cannot create Collection from response that does not have resources” error in my logs, and trying to investigate why…

Any luck with this? Im starting to see that now also.