Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Why does the function fail after UrlFetchApp.fetchAll () is executed?

After executing the useFetchAll function, I pass the response value to the stringform function, and I get an error

TypeError: A.forEach is not a function

In the example, I made the variable asdf and copied the Logger.log (response) value into it, the stringform function works and returns an array. Why does the function throw an error when the value is (response)?

    // Using UrlFetchApp.fetchAll()
    function useFetchAll(req) {
    var response = UrlFetchApp.fetchAll(req);
     
    var asdf=[[["a",1],["a",2],["a",3],["a",4],["a",5]], [["b",6],["b",7],["b",8],["b",9],["b",10]], [["c",11],["c",12],["c",13],["c",14],["c",15]], [["d",16],["d",17],["d",18],["d",19],["d",20]], [["e",21],["e",22],["e",23],["e",24],["e",25]]];
     
    Logger.log(response);
    Logger.log(stringform(asdf));
     
    }
     
    
   function stringform(asdf) {
    let formad = '';
      asdf.forEach(A => {
        A.forEach(r => {
          formad += r.join(',') + '%0A';
        });
      });
      return formad;
      
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It's an array that's 3 deep.

function myfunction() {
  let s = '';
  var asdf = [[["a", 1], ["a", 2], ["a", 3], ["a", 4], ["a", 5]], [["b", 6], ["b", 7], ["b", 8], ["b", 9], ["b", 10]], [["c", 11], ["c", 12], ["c", 13], ["c", 14], ["c", 15]], [["d", 16], ["d", 17], ["d", 18], ["d", 19], ["d", 20]], [["e", 21], ["e", 22], ["e", 23], ["e", 24], ["e", 25]]];
  asdf.forEach(A => {
    A.forEach(r => {
      s += r.join(',')+ '\n';
    })
  })
  Logger.log(s);
}

Execution log
3:53:29 PM  Notice  Execution started
3:53:29 PM  Info    a,1
a,2
a,3
a,4
a,5
b,6
b,7
b,8
b,9
b,10
c,11
c,12
c,13
c,14
c,15
d,16
d,17
d,18
d,19
d,20
e,21
e,22
e,23
e,24
e,25
3:53:30 PM  Notice  Execution completed

You lower function would have worked but asdf was not defined in that function.

Your lower function runs like this:

function stringform(asdf) {
  var asdf = [[["a", 1], ["a", 2], ["a", 3], ["a", 4], ["a", 5]], [["b", 6], ["b", 7], ["b", 8], ["b", 9], ["b", 10]], [["c", 11], ["c", 12], ["c", 13], ["c", 14], ["c", 15]], [["d", 16], ["d", 17], ["d", 18], ["d", 19], ["d", 20]], [["e", 21], ["e", 22], ["e", 23], ["e", 24], ["e", 25]]];
    let formad = '';
      asdf.forEach(A => {
        A.forEach(r => {
          formad += r.join(',') + '\n';
        });
      });
      Logger.log(formad)
      
    }
about 4 years ago · Juan Pablo Isaza Report

0

About your question of Why does the function fail after UrlFetchApp.fetchAll () is executed?, from your script and In the example, I made the variable asdf and copied the Logger.log (response) value into it, the stringform function works and returns an array. Why does the function throw an error when the value is (response)?, I thought that the reason of your issue is due to that fetchAll returns HTTPResponse[] which is an array.

For example, when one of requests req returns 2 dimensional array like [["a",1],["a",2],["a",3],["a",4],["a",5]], Logger.log(response) of var response = UrlFetchApp.fetchAll(req) shows [[["a",1],["a",2],["a",3]], [["a",1],["a",2],["a",3]]]. In your situation, I thought that the values from the muliple requests might be included in response.

If my understanding of your situation is correct, how about the following modification?

Modified script:

function useFetchAll(req) {
  var response = UrlFetchApp.fetchAll(req);
  var asdf = response.map(r => JSON.parse(r.getContentText()));
  Logger.log(stringform(asdf));
}

function stringform(asdf) {
  let formad = '';
  asdf.forEach(A => {
    A.forEach(r => {
      formad += r.join(',') + '%0A';
    });
  });
  return formad;
}

or,

function useFetchAll(req) {
  var response = UrlFetchApp.fetchAll(req);
  var values = response.reduce((t, r) => t += JSON.parse(r.getContentText()).map(c => c.join(',') + '%0A'), "");
  Logger.log(values)
}

Reference:

  • fetchAll(requests)

    Return: HTTPResponse[] — An array of HTTP response data from each input request.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!