auth0 / go-auth0

Go SDK for the Auth0 Management API.
https://auth0.com
MIT License
135 stars 54 forks source link

Organizations.List request has bugs with checkpoint paginations params input #109

Closed sambhavjain9138 closed 1 year ago

sambhavjain9138 commented 2 years ago

Describe the problem

While making auth0 call to list all organization, we are getting unexpected results.

Request:

                 Auth0Client.Organization.List(
             management.From(<prev next>),
        )

When we dont send Take, the Limit is set to 50, but in each request, we dont get a Next value. Start is always set to 0, next to empty string and total to the number of documents.

When we do send Take (i did set it as 10, then 50), it send start, limit, length, total as 0 and next as a string and with organizations list. First 50 organizations.

Similar issue: https://github.com/auth0/auth0-python/issues/277

What was the expected behavior?

To get next value for list request and proper params for the same with Take value

Reproduction

The error is reproducible. Making a call to the following function would help. https://github.com/auth0/go-auth0/blob/main/management/organization.go#L187

Environment

sambhavjain9138 commented 2 years ago

@sergiogarcia0 Can you please help with this?

sergiught commented 1 year ago

Hey @sambhavjain9138 👋🏻

Apologies for the late reply. I took a look at this but wasn't able to spot any issues. There's a difference between offset pagination and checkpoint pagination.

When you use Take and From you're going to get back the checkpoint pagination result, that doesn't include total, start and limit.

From the docs:

List available organizations. This endpoint supports two types of pagination:

  • Offset pagination
  • Checkpoint pagination

Checkpoint pagination must be used if you need to retrieve more than 1000 organizations.

Checkpoint Pagination

To search by checkpoint, use the following parameters:

  • from: Optional id from which to start selection.
  • take: The total amount of entries to retrieve when using the from parameter. Defaults to 50.

Note: The first time you call this endpoint using Checkpoint Pagination, you should omit the from parameter. If there are more results, a next value will be included in the response. You can use this for subsequent API calls. When next is no longer included in the response, this indicates there are no more pages remaining.