node-asana icon indicating copy to clipboard operation
node-asana copied to clipboard

Fix: expose next_page at top level for paginated endpoints

Open RaoUsama7 opened this issue 4 months ago • 1 comments

Pull Request: Make next_page available in paginated responses Overview

This PR addresses the pagination defect in the Asana Node.js SDK where pagination metadata (next_page) existed only within the internal _response object, which was inconvenient for users to access paginated endpoints. With this update, next_page is exposed at the top level of the SDK response, which aligns with the Asana API documentation.

Changes Included

In the Collection / Resource / Response constructor (e.g. in src/utils/collection.js or src/resource_response.js), added logic to elevate this._response.next_page to this.next_page when it exists.

Added unit and integration tests: test/utils/collection.spec.js — tests exposing next_page, handling no pagination, edge cases. test/integration/pagination.spec.js — end-to-end tests for UsersApi.getUsers() and other paginated endpoints.

Added example script examples/pagination_example.js to illustrate usage.

Documentation update / summary in PAGINATION_FIX_DOCUMENTATION.md (optional but preferred).

How to Test / Validate

Run the full test suite:

npm test

All current tests must work; the new pagination tests must work too.

Use the example:

node examples/pagination_example.js It must retrieve more than one page (if your team/account has more than one page) and log next_page objects.

Manual sanity check:

const result = await usersApi.getUsers({ team: 'TEAM_ID', limit: 1 });
console.log(result.next_page);  // should be defined if more pages

Backward Compatibility & Behavior

The internal _response object remains in place; code that currently uses res._response.next_page will remain functional.

No API break — we aren't changing method signatures or eliminating working functionality.

The nextPage() helper (if it exists) still works the same way as before (if implemented in SDK).

Related Issue / Context

This resolves the outstanding question regarding pagination visibility in UsersApi.getUsers() and such SDK endpoints. Users manually had to unpack res._response.next_page in their app code. This PR brings SDK behavior in line with the official Asana API spec.

Notes / Considerations

There could be other SDK methods or endpoints taking the same Collection / Response pattern (e.g. Tasks, Projects). It's suggested to make sure this pattern is spread throughout all paginated endpoints.

In SDK auto-generated code generation pipelines, this patch should be taken into account while regenerating client libraries for future releases.

RaoUsama7 avatar Oct 10 '25 22:10 RaoUsama7

@Asana @barryam3 — This PR fixes the pagination accessibility issue where next_page was not exposed at the top level. This aligns SDK behavior with Asana API documentation.

RaoUsama7 avatar Oct 10 '25 22:10 RaoUsama7