Search code examples
javascriptnode.jssmartsheet-api

Working With SmartSheets API, Loop Through List for Variable of a Function


I have a list of numbers like below stored into a variable.

[700000000084,
100000000051652,
8800000000000072,
280000000000004,
680000000000008,
880000000000006]

I am trying to loop this through the SmartSheets API to pull all the info I need into one block of data.

var options = {
  id: 8800000000000072 // ID of Sheet
};

// Get sheet as CSV.
smartsheet.sheets.getSheetAsCSV(options)
  .then(function(data) 
  {
    console.log(data);
  })
  .catch(function(error) 
  {
    console.log(error);
  });

What would be the most efficient way to loop the list into

var options = 
{
  id: IDLoop // ID of Sheet
};

All the while, when the new number is in the options parameters to run the function and collect the data, I need to do this with all the numbers in the list and collect all of the data it produces.

Any advice to the most efficient way to do this?
I am assuming I will need to do some sort of loop, but any advice would be great.


Solution

  • Have you tried using a for loop like this?

    var options = [700000000084,
    100000000051652,
    8800000000000072,
    280000000000004,
    680000000000008,
    880000000000006]
    
    for (var i = 0; i < options.length; i++) {
    
    	// Get sheet as CSV.
    	smartsheet.sheets.getSheetAsCSV(options[i])
    	  .then(function(data) 
    	  {
    	    console.log(data);
    	  })
    	  .catch(function(error) 
    	  {
    	    console.log(error);
    	  });
    
    }