Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

374
Vistas
Google API - using nextPageToken to return all pages via node command line

We are developing some command line Google API scripts via node.js, and I'm having a hard time understanding the following:

Given this code to return the max number of our Google Groups in a single call (200):

// auth object, creds, scopes, async, etc. are above and working

const getAllGroups = await googleAdminDir.groups.list({
    auth,
    domain: "ourDomain.com",
    nextPageToken: "nextPage",
});

Say I have a variable number of groups. How would I (sanely) utilize nextPageToken to keep repeating the request until there are no more returned results?

I haven't found yet an API endpoint so far that I could call to find data that says You have *This* many groups in your domain. So my best attempt so far is something like:

const getAllGroups = await googleAdminDir.groups.list({
    auth,
    domain: "myDomain.com",
    nextPageToken: "nextPage",
}).then(resp =>{

    let returnData = resp.data.groups;
    let pageToken = data.data.nextPageToken;

    return googleAdminDir.groups.list({
        auth,
        domain: "myDomain.com",
        nextPageToken: "pageToken",
    });

}).then(resp =>{

    let returnData = resp.data.groups;
    let pageToken = data.data.nextPageToken;

    // Create .then() clauses until it errors, 
    // then create some way to stop it before the error is thrown?
    // TODO: Hide that I did it this way 

});

The above idea is....bad, and what I need help remedying. I probably missed something simple or have a "Why would you ever do it that way.....?" in here. Please enlighten me if so, I'll be humble :)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda