Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor/limit functionality not available through the SDK? #613

Open
acomito opened this issue Dec 24, 2024 · 2 comments
Open

Cursor/limit functionality not available through the SDK? #613

acomito opened this issue Dec 24, 2024 · 2 comments
Labels

Comments

@acomito
Copy link

acomito commented Dec 24, 2024

The docs reference a "limit" field that doesn't seem to exist in queryParams anymore.

This reference the new cursor ability but I don't think the SDK has a field for it either

https://developer.nylas.com/docs/v2/upgrade-to-v3/features-and-changes/

@acomito acomito added the bug label Dec 24, 2024
Copy link

Hi! I've investigated this issue and found that this appears to be a documentation/naming mismatch rather than missing functionality:

  1. The limit field IS actually available in queryParams (see src/models/listQueryParams.ts)
  2. The cursor functionality IS implemented but under a different name:
    • V3 API docs refer to it as cursor
    • SDK implements it as pageToken

The functionality works exactly as described in the V3 upgrade documentation, just with a slightly different parameter name in the SDK. Here's how to use it:

When making paginated requests:

  1. First request: Use limit without pageToken
  2. Subsequent requests: Use the nextCursor value from the previous response as the pageToken parameter

The functionality is fully implemented and working, it's just that the parameter name in the SDK (pageToken) differs from what's mentioned in the V3 upgrade docs (cursor).

You can find the implementation in:

  • src/models/listQueryParams.ts (interface definition)
  • src/resources/resource.ts (pagination implementation)

@j0nas
Copy link

j0nas commented Jan 23, 2025

For what it's worth, I just got through being tripped up by this. I could not find anything in the docs mentioning anything accepting a nextCursor. I searched for "nextCursor", "cursor", "next". The docs should feature an example fetching multiple records.

This is my current implementation:

export const fetchNylasEvents = async (
  grantId: string,
  calendarId: string,
  startTime: string,
  endTime: string,
): Promise<NylasEvent[]> => {
  const events: NylasEvent[] = [];
  let pageToken: string | undefined;
  let pageCount = 0;

  try {
    do {
      const response = await nylasClient.events.list({
        identifier: grantId,
        queryParams: {
          start: startTime,
          end: endTime,
          calendarId,
          select: 'title,description,location,status,when',
          ...(pageToken && { pageToken }),
        },
      });

      events.push(...response.data);
      pageToken = response.nextCursor;
      pageCount++;

      console.debug(
        `Fetched page ${pageCount} of events (${response.data.length} events)`,
      );
    } while (pageToken);

    console.debug(
      `Total events fetched: ${events.length} in ${pageCount} pages`,
    );
    return events;
  } catch (error) {
    console.error('Error fetching Nylas events:', error);
    throw new Error(
      `Failed to fetch Nylas events: ${error instanceof Error ? error.message : String(error)}`,
    );
  }
};

But it would've been good to see the docs mentioning such a common usecase.

EDIT: What's more, the API fails with a generic response if I pass pageToken: undefined. Updated my function above to account for this, now it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants