Problem with next_page

Hello community,
I have the following issue whit “get multiple tasks in a project”. The ‘uri’ field in the JSON pagination is coming as None, and I haven’t been able to go through all the pages to retrieve all the tasks.

image

i get only 200 task with this code, I know that exist more than 1000 task
configuration = asana.Configuration()
configuration.access_token = ‘Token’
api_client = asana.ApiClient(configuration)

create an instance of the API class

tasks_api_instance = asana.TasksApi(api_client)
opts = {
‘limit’: 100, # int | Results per page. The number of objects to return per page. The value must be between 1 and 100.
‘project’: “1203703961124463”, # str | The project to filter tasks on.
‘opt_fields’: “gid,name,completed_at”}

try:
# Get multiple tasks
api_response = tasks_api_instance.get_tasks(opts)
i=1
for data in api_response:
print(i)
pprint(data)
i=i+1
except ApiException as e:
print(“Exception when calling TasksApi->get_tasks: %s\n” % e)

I changes the code with limit = 95 and i can get de all task
but when I put limit = 100, I get only 200 task

Hey @Diego_Ramírez ,

If you’re using the Python client library, pagination is already handled for you. So you could leave the ‘limit’ parameter out of opts altogether and the function should retrieve all tasks in the project.

You can also disable the auto-pagination feature. More details on all of this in python-asana/README.md at master · Asana/python-asana · GitHub (search the page for Pagination).

2 Likes

Hi @Diego_Ramírez,

It looks like you are using our python-asana v5 client library to make your request. As @tjholsman mentioned pagination is enabled by default for v5.

This means that you do not need to provide a limit argument in the query param.

I also tried to reproduce your issue by providing "limit": 95 and "limit":100 and was not able to reproduce your issue.

Here’s a scenario using default auto pagination:

  1. I have a project with 1010 tasks (Let’s call this project 123)
  2. I make an API call with using python-asana v5 client library:
import os
import asana
from asana.rest import ApiException

configuration = asana.Configuration()
configuration.access_token = os.environ["ASANA_PERSONAL_ACCESS_TOKEN"]
api_client = asana.ApiClient(configuration)

# create an instance of the API class
tasks_api_instance = asana.TasksApi(api_client)
opts = {
    'project': "123",
}

try:
    # Get multiple tasks
    api_response = tasks_api_instance.get_tasks(opts)
    count = 0
    for data in api_response:
        count += 1

    print(f"Total tasks: {count}")
except ApiException as e:
    print("Exception when calling TasksApi->get_tasks: %s\n" % e)

I get back the following output:

Total tasks: 1010

If you would like to disable the auto-pagination feature for v5 and just get the pages yourself see Disabling default pagination behaviour


One thing that could explain your issue is we recently found a bug (Get tasks from a project returns different number of tasks depending on page limit provided) in our API for paginated requests where if the limit you provide ends in the section of a project it causes the next_page to cut off early. By default, our auto pagination specifies a limit of 100 so you may encounter the same issue if you use auto pagination.

Here’s an example scenario:

  • PROJECT_A has a section called SECTION_1
  • PROJECT_A has. a section called SECTION_2
  • SECTION_1 has 5 tasks
  • SECTION_2 has 10 tasks
  • If you make a call to Get multiple tasks endpoint and specify a limit of 5 the API will return next_page of null after those 5 tasks → technically this should not happen and it should return 15 tasks, so this is the bug that we are currently fixing.

To get around this, I recommend changing the default limit like you have to a limit that doesn’t end in a section or make a non-paginated request (turn off auto pagination feature and make a request without a limit query param —> Caveat if a project has more than 1000 tasks this will throw an error and tell you to use pagination)

2 Likes

Hi @Diego_Ramírez , we have fixed the pagination issue with the sections so this issue with next_page should be resolved. Let us know if you still encounter this issue.

1 Like

Hi @John_Vu I am experiencing an issue that may be related. I am running the following code and return varying results. The 1st time i refresh the IDE and run the following script it returns the full list of tasks in my project. Each time after i call the same call it returns less tasks but the same.

1st call = full list (125)

2nd and 3rd call = (25)

def run():
    try:
        # Get tasks from a section
        api_response = tasks_api_instance.get_tasks_for_project(gid, opts)
        data_list = []
        for data in api_response:
            data_list.append(data)
        return data_list
    except ApiException as e:
        print("Exception when calling TasksApi->get_tasks_for_section: %s\n" % e)

ass = run()

len(ass)

ass2 = run()
ass3 = run()

len(ass)      (this is 125)
len(ass2)    (this is 25)
len(ass3)    (this is 25)

ass2 == ass3    (this is true)

Hi @Erik_Deger,

What IDE are you using? Also, I noticed that there is a comment for # Get tasks from a section (i.e., Get tasks from a section), but the actual API call is get_tasks_for_project . Is this right?

I tried to reproduce this myself with the script you shared but could not. Can you give us more details about your script and how you have your project set up? Once we can reproduce the issue, we can debug it and fix the problem.