Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

376
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda