Search API + Pagination issue -- Help needed!

Hi everyone,

I have the following issue :
https://app.asana.com/api/1.0/workspaces/XXXXXXXX/tasks/search?tags.any=762530330245060,762530330245061,762530330245064,762530330245054&opt_fields=name,tags,completed,assignee

I want to search my workspace and find all tasks that have any of these four tags assigned to them. I then extract all the output and build a little dashboard out of it which enables me to monitor the backlog + bottlenecks in our operations.

This seems to work just fine, as long as the results are not exceeding the output limit of 100. The official documentation (https://asana.com/developers/documentation/getting-started/search-api) states the following regarding to pagination:

Blockquote
Search results are not stable; repeating the same query multiple times may return the data in a different order, even if the data do not change. Because of this, the traditional pagination available elsewhere in the Asana API is not available here. However, you can paginate manually by sorting the search results by their creation time and then modifying each subsequent query to exclude data you have already seen. Page sizes are limited to a maximum of 100 items, and can be specified by the limit query parameter.
Blockquote

The statement in bold tells me what to do in that case. However, I am clueless how to implement that correctly into my current API request to achieve that goal.

A tip to resolve this issue would be highly appreciated.

Thank you very much,
Max

2 Likes

Hi,

If I understand correctly, in addition to the tags as a search field, you should add a field about the creation time (between A and B). And then for the next request, B becomes the lower limit and C is the new upper limit… and so on.

Does it make sense?

Bastien

Bastien
Asana Certified Pro, consultant, author and developer

Hey Bastien,

thanks for your feedback. I modified the API request and it works :slight_smile:

https://app.asana.com/api/1.0/workspaces/IAmSecret/tasks/search?tags.any=762530330245060,762530330245061,762530330245064,762530330245054,780689724042204&opt_fields=name,tags,completed,assignee&created_on.after=2018-07-01&created_on.before=2018-07-08

However, this workaround would imply, that I have to run the request for every calendar week in the year to get the results. Also, the moment we scale our operations to above 100 new tasks per week, this solution is impractical.

Is there any chance to increase the “limit” to 1.000 (10.000) for single accounts? Requests would be send once every other month. If there is a fee needed for it we’d be happy to cover it.

Thank you very much,
Max

1 Like

Or you run the request with A and B, and if you have more than 100 results, you run A-B/2 and so on… But the code will be crazy :sweat_smile:

Exactly. Also I am not a professional coder, just a kid who is utilizing Excel + JSON AddIn.

Whom could I talk to regarding my specific problem, as I am still waiting for a response on my previous question :)!?

Asana does not provide official help with the API, appart from the existing doc. So either we keep iterating in the community, or you hire an expert. You can find most of them on iDO Tools - Improve Asana with our tools and automations

Hey all,

We don’t have any current plans to increase the size of pagination limits for premium accounts or anything like that (and this might be only a temporary fix, since any arbitrary number could end up being too small in the future). However, there’s a fairly simple and more efficient approach that will help here.

If you look in the docs for our search API you can find the section on sorting using the sort_by parameter. When we talk about pagination with the creation date, what we mean is something like including the created_on.after parameter and the sort_by parameter (but not created_on.before) to get the first 100 tasks created after that date.

Then you can make another request with created_on.after set as the latest date you got from any task in the first request, and keep repeating until you get an empty result (i.e. there are no tasks created after a date that is very close to “now”).

Rather than hoping that no more than 100 tasks will be created for a particular time span (like a week), this approach will always return 100 tasks at a time if possible until you’ve paginated through the whole set of tasks.

(Also of note, we do have an in-house services team that can build API scripts for customers, but this integration sounds straightforward enough that we hope you can get there without too much more effort and time! Those of us in our Developer Relations and API teams poke our heads into the forum from time to time whenever we have the bandwidth, though of course the other users on the forum like @Bastien_Siebman are a great source of knowledge in between times we can get on here!)

3 Likes

Good to know!