Task count from API endpoint doesn't match tasks count on Asana reporting

Hi all, I tried to retrieve the number of tasks on this project named Engineer RoadMap by sending a simple get requests to this endpoint (I believe this gets both complete and incomplete tasks)

curl --request GET \
     --url "https://app.asana.com/api/1.0/projects/${project_id}/tasks" \
     --header 'accept: application/json' \
     --header "authorization: Bearer ${api_token}" | jq '.data | length'

results:
231

I double-checked with the Asana reporting, and turns out this number isn’t any close to the one I got


(I can only upload 1 image. On Asana reporting, there’re ~8600 completed tasks, and ~1000 incomplete tasks)

I thought the Asana reporting might also include the sub-tasks. Hence I wrote a bash script to get all the subtasks, and eventually get this number
259
Adding up with the total tasks above, I only got ~500 tasks and subtasks in total via API call. Meanwhile, the Asana reporting shows up to ~1000 tasks incomplete, and ~8600 tasks completed.

Is there something wrong with the Asana API? Or this has something to do with the Asana reporting? Thank you!

Sorry for the confuse asana reporting title. Cannot edit so I re-up the report screenshot here

Welcome, @Triet_Le,

I think the issue is that your request should be using pagination (probably easier via a client library than with cURL) so you’re not seeing all the results via your API call.

More info is found here:

Hope that helps,

Larry

3 Likes

If your projects are huge and you only need the count, not tasks, you can also use that endpoint, to get statistics about your project.

2 Likes

@Ipb
Thanks for the info. I was quite aware of the pagination mechanism. I noticed for the above endpoint that I made, since I didn’t put the param limit into the query, all the tasks are returned already and no key-value offset is presented within my API call response.


As you see, at the end of the response, there is no offset key-value.

@Frederic_Malenfant
Thank you for letting me know about the above endpoint. I just tried it with my project_id and seems like that API endpoint doesn’t work :frowning: It returns no data

No, that’s not how Asana’s pagination works. As the docs say, if you don’t include a limit parameter, you will get partial and inconsistent results; that is, you’ll get some initial portion of the requested data but not all of it, and the amount of data returned is likely to be inconsistent between successive non-paginated calls.

You’ll only get back the pagination info (next_page) if you include the limit parameter.

Bottom line: if you want to get more than 50-100 tasks back, you need to use pagination and that means including the limit parameter.

1 Like

You missed this part of the docs regarding the task counts endpoint:

All fields are excluded by default . You must opt in using opt_fields to get any information from this endpoint.

3 Likes

Hi Phil, thank you for clarifying. I tried filling in limit = 100 and keep using pagination to request the next page. Pagination didn’t go further 3 pages, and the total number of tasks seems like didn’t change much :frowning:

I tried again with the tasks_count endpoint by filling in opt_fields as what you told (sorry I missed this part)

You missed this part of the docs regarding the task counts endpoint:

The result reflected what I’ve observed, it still showed a total of only 231 tasks - exactly what I got lately.
image

Back to the root issue, this API endpoint’s response is hugely deflected from the Asana reporting. Honestly, I’m not sure what has been wrong here. Is there something you could help me out with this?

I don’t use reporting or the task count endpoint so I’m not sure how either of those are calculated.

If you go to the actual project in the Asana web application, how many tasks are actually in the project? How many subtasks? Is it in the neighborhood of 250-260, or is it wayyyy bigger than that, in the neighborhood of 8000-9000 (though I don’t expect you to count all of them exactly if it’s that big).

1 Like