Pagination with the Java client (Maven dependency version 0.10.1)

I’m having trouble understanding how to work with pagination with the Java client. I followed the instructions on Asana and set up the Maven dependency for version 0.10.1.

I’m able to get a list of tasks for a project with:

List projectTasks = client.tasks.getTasksForProject(myProject.gid, null, null, null, true)
.option(“pretty”, true)

The issue is that I don’t know how to get the “nextPage” or “offset” data that I’m sure is somewhere in the response.

I tried changing the return type from client.tasks.getTasksForProject to:
CollectionRequest projectTasks = client.tasks.getTasksForProject(myProject.gid, null, null, null, true).option(“pretty”, true).execute();

But then I get a compilation error that CollectionRequest is not a return type for that call.

I looked at this post Pagination in Java client and ResultBodyCollection gives me the same compilation error. Only a List is returned from the client.tasks.getTasksForProject call. And when I try to get nextPage from the List object it also gives a compilation error.

Is there an updated version of the Maven dependency? Is there a different object that I should be casting the return to? Is there another way to get nextPage and offset with the version I have?

Thanks for any help!

Figured out my error. I was using .execute() when I needed to use .executeRaw() and then use the .data for the List<> to iterate over.

Also found the github project for the Java client (GitHub - Asana/java-asana: Official Java client library for the Asana API v1) and updated to the most recent version (0.10.12)

This code works now:

       // result.nextPage.offset is offsset for pagination
        CollectionRequest<Task> request = client.tasks.getTasksForProject(myProject.gid, null)
                .option("pretty", true);
        ResultBodyCollection<Task> result = request.executeRaw();
        List<Task> projectTasks =;
        for (Task temp : projectTasks) {
            LOGGER.debug("gid =" + temp.gid + " name =" +;
        if (result.nextPage != null) {
            // need to handle pagination if nextPage is not null
            LOGGER.debug("offset = " + result.nextPage.offset);
1 Like