title: Multiple paginated GET API calls in parallel/async in Node
body: <p>I am making call to the bitbucket API to get all the files that are in a repo. I have reached to a point where I can get the list of all the folders in the repo and make the first API call to all the root folders in the repo in parallel and get the the list of first 1000 files for all folders. </p>
  
  <p>But the problem is bitbucket api can give me only 1000 files per folder at a time. </p>
  
  <p>I need to append a query param &amp;start =nextPageStart and make the call again, until it is null and isLastPage is true per API. How can I achieve that with below code??</p>
  
  <p>I get the nextPageStart from first call to the api. See the API response below.</p>
  
  <p>Below is the code that I have so far.</p>
  
  <p>Any help or guidance is appreciated.</p>
  
  <blockquote>
    <p>Response from individual API thats called per folder.</p>
  </blockquote>
  
  <pre><code>{
      "values": [
          "/src/js/abc.js",
          "/src/js/efg.js",
          "/src/js/ffg.js",
          ...
      ],
      "size": 1000,
      "isLastPage": false,
      "start": 0,
      "limit": 1000,
      "nextPageStart": 1000
  }
  </code></pre>
  
  <blockquote>
    <p>function where i made asynchronous calls to get the list of files</p>
  </blockquote>
  
  <pre><code>export function getFilesList() {
    const foldersURL: any[] = [];
    getFoldersFromRepo().then((response) =&gt; {
      const values = response.values;
      values.forEach((value: any) =&gt; {
      //creating API URL for each folder in the repo
        const URL = 'https://bitbucket.abc.com/stash/rest/api/latest/projects/'
                     + value.project.key + '/repos/' + value.slug + '/files?limit=1000';
        foldersURL.push(URL);
          });
      return foldersURL;
        }).then((res) =&gt; {
      // console.log('Calling all the URLS in parallel');
      async.map(res, (link, callback) =&gt; {
         const options = {
           url: link,
           auth: {
             password: 'password',
             username: 'username',
           },
         };
         request(options, (error, response, body) =&gt; {
  
        // TODO: How do I make the get call again so that i can paginate and append the response to the body till the last page.
  
           callback(error, body);
         });
       }, (err, results) =&gt; {
         console.log('In err, results function');
         if (err) {
           return console.log(err);
         }
         //Consolidated results after all API calls.
         console.log('results', results);
       });
    })
     .catch((error) =&gt; error);
  }
  </code></pre>