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

**URL:** <https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153>\
**Category:** API & Developers\
**Tags:** projects, tasks\
**Created:** [31 August 2021 10:28 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153 "2021-08-31T10:28:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lamine\_B](https://luna1.co/8d76cd.png) [@Lamine\_B](https://forum.asana.com/u/Lamine_B)\
**Post date:** [31 August 2021 10:28 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/1 "2021-08-31T10:28:34Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [31 August 2021 18:48 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/2 "2021-08-31T18:48:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lamine\_B](https://luna1.co/8d76cd.png) [@Lamine\_B](https://forum.asana.com/u/Lamine_B)\
**Post date:** [31 August 2021 19:47 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/3 "2021-08-31T19:47:36Z")

</div>

Thank you for your help.

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

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [31 August 2021 19:56 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/4 "2021-08-31T19:56:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Lamine\_B](https://luna1.co/8d76cd.png) [@Lamine\_B](https://forum.asana.com/u/Lamine_B)\
**Post date:** [31 August 2021 20:32 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/5 "2021-08-31T20:32:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [31 August 2021 22:36 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/6 "2021-08-31T22:36:05Z")

</div>

Looking at the source for the Node library:

> <https://github.com/Asana/node-asana/blob/8db5f44ff9acb8df04317c5c4db0ac4a300ba8b0/lib/util/collection.js#L21>

It says:

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

```

---

<div class="post-metadata">

**Author:** ![Lamine\_B](https://luna1.co/8d76cd.png) [@Lamine\_B](https://forum.asana.com/u/Lamine_B)\
**Post date:** [1 September 2021 04:54 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/7 "2021-09-01T04:54:23Z")

</div>

Thank you very much for your help.

I’ll try it and let you know.

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [1 September 2021 05:59 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/8 "2021-09-01T05:59:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![User11](https://luna1.co/8d76cd.png) [@User11](https://forum.asana.com/u/User11)\
**Post date:** [1 September 2021 06:38 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/9 "2021-09-01T06:38:36Z")

</div>

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](https://github.com/Asana/node-asana/) but unfortunately, it is not bringing all tasks.

Someting looks strange/broken

---

<div class="post-metadata">

**Author:** ![User11](https://luna1.co/8d76cd.png) [@User11](https://forum.asana.com/u/User11)\
**Post date:** [1 September 2021 06:41 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/10 "2021-09-01T06:41:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lamine\_B](https://luna1.co/8d76cd.png) [@Lamine\_B](https://forum.asana.com/u/Lamine_B)\
**Post date:** [1 September 2021 06:52 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/11 "2021-09-01T06:52:49Z")

</div>

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

```auto
{ 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

---

<div class="post-metadata">

**Author:** ![Lamine\_B](https://luna1.co/8d76cd.png) [@Lamine\_B](https://forum.asana.com/u/Lamine_B)\
**Post date:** [1 September 2021 20:39 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/12 "2021-09-01T20:39:28Z")

</div>

Hi @Larry_Berger_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

---

<div class="post-metadata">

**Author:** ![Larry\_Berger\_lpb](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/larry_berger_lpb/32/276017_2.png) [@Larry\_Berger\_lpb](https://forum.asana.com/u/Larry_Berger_lpb)\
**Post date:** [2 September 2021 01:48 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/13 "2021-09-02T01:48:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [2 September 2021 02:50 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/14 "2021-09-02T02:50:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [2 September 2021 10:40 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/15 "2021-09-02T10:40:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andre\_Lung](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/andre_lung/32/60792_2.png) [@Andre\_Lung](https://forum.asana.com/u/Andre_Lung)\
**Post date:** [5 September 2021 18:41 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/16 "2021-09-05T18:41:41Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![User11](https://luna1.co/8d76cd.png) [@User11](https://forum.asana.com/u/User11)\
**Post date:** [5 September 2021 21:13 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/17 "2021-09-05T21:13:41Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [6 September 2021 02:22 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/18 "2021-09-06T02:22:14Z")

</div>

> [@User11](#):
>
> He told me that Asana limits to 15/min the number of records (tasks in our case) you can pull using API

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:

> **[Rate limits](https://developers.asana.com/docs/rate-limits)**
>
> 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...

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.

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [29 January 2023 17:59 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/19 "2023-01-29T17:59:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Jonas\_O](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jonas_o/32/12844_2.png) [@Jonas\_O](https://forum.asana.com/u/Jonas_O)\
**Post date:** [22 March 2023 09:33 UTC](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153/20 "2023-03-22T09:33:55Z")

</div>

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

[Next page](https://forum.asana.com/t/when-trying-get-all-tasks-for-project-using-recursive-function-asana-not-returning-all-tasks/134153.md?page=2)
