0

We are trying to receive information about customers, all we get is 20 results, would like to search next page as well. Should loop through all pages until null, but can't create a loop when using the web explorer, or?

What value should be paste to receive all results? (Leaving pageToken field empty only gives us 20 results. enter image description here

https://developers.google.com/admin-sdk/reseller/v1/reference/subscriptions/list#try-it

John Smith
  • 387
  • 2
  • 8
  • 24

3 Answers3

3

Your problem is that you are specifying fields=, but haven't included nextPageToken as one of the fields. That is why there is no nextPageToken present in the response. By adding nextPageToken (or omitting fields completely(v2) or setting fields=* (v3)), your first page of results will include a nextPageToken, which you will provide as the value of pageToken for your next call. Rinse, repeat until you get a response with no nextPageToken. For your first call, of course pageToken is blank.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • I know this is old, but just wanted to say thank you for pointing this out. I'm really surprised that it's necessary to include this, and it's not included in the responses by default. I was pulling my hair out wondering why my pagination stopped working after adding fields. – Mike Wilson Jun 27 '19 at 02:19
0

In order to get more than 20 results, you have have to provide some value in "maxResults" parameter.

maxResults(unsigned integer): When retrieving a large list, the maxResults is the maximum number of results per page. The nextPageToken value takes you to the next page. The default is 20. Acceptable values are 1 to 100, inclusive.

Please check this page for reference: https://developers.google.com/admin-sdk/reseller/v1/reference/subscriptions/list

Hope that helps!

KRR
  • 4,647
  • 2
  • 14
  • 14
  • Damnit you Reputation-hunters on stack.. No of course, all you just wrote stands clear on the page, I have more than 100 results of course, standard is just 20. Set it to 100 just gives us 100.. But we need to go to the nextpage, since we have more than 100 results. nextPageToken does NOT takes us to the next pages as demostrated in the printscreen, we recieve an error, what should we type in PageToken? – John Smith Mar 31 '15 at 21:44
  • You don't have to blame me for pointing out the documentation. I am just pointing to the right direction. – KRR Mar 31 '15 at 22:46
  • If there are more results than the value given in the 'maxResults' there will be a value for 'nextPageToken' in the response and pass the same value into the new request as pageToken to loop over the next set of results. Please do verify what you are getting the value for 'nextPageToken' in your initial response for the request. and the same value has to be used for 'pageToken' in next request. Please do check the documentation for property name and description. – KRR Mar 31 '15 at 23:05
0

From one John to another...

I didn't call the REST HTTP endpoint directly, but when using the G Suite Directory API Client Library I needed to loop thru multiple pages to receive all results.

This is the pattern I used. It would be very similar for the G Suite Reseller API.

/// <summary>
/// List all Members in a Domain Group.
/// <param name="service">DirectoryService object (Google Directory API)</param>
/// <returns>Collection of Member emails</returns>
/// </summary>
public IEnumerable<string> ListGroupMembers(DirectoryService service)
{
    // Set Group key (email address of the Group or id of the Group)
    var groupKey = "email-for-google-group@domain-name.com";

    // Define parameters of request (Group email)
    MembersResource.ListRequest request = service.Members.List(groupKey);

    // Sadly, this won't work
    request.MaxResults = int.MaxValue;

    // And the max page size of response is ONLY 200!

    // So you have to check for the next page token
    // and execute another request if there is one

    do
    {
        // Get Members response for this Group
        Members response = request.Execute();

        // Return the emails in this response page
        foreach (var member in response.MembersValue)
        {
            yield return member.Email;
        }

        // Get next page token
        request.PageToken = response.NextPageToken;

        // Continue loop if next page token is not null
    } while (!string.IsNullOrEmpty(request.PageToken));
}
JohnB
  • 18,046
  • 16
  • 98
  • 110
  • On a somewhat related note, you can't use `MembersResource.HasMemberRequest request = _directoryService.Members.HasMember(groupKey, memberEmail);` because `HasMember()` does not work if memberKey belongs to a domain outside of groupKey domain. https://issuetracker.google.com/issues/109861216 – JohnB Nov 06 '18 at 05:49
  • So to check if member exists in domain group: `ListGroupMembers().Any(x => x == memberEmail);` which is a heavy call just to check for 1 member. – JohnB Nov 09 '18 at 17:29