I am looking to run below app script with multiple var url such as
https://www.testurl.com/link1=processing
https://www.testurl.com/link2=processing
https://www.testurl.com/link3=processing
How to add multiple url to below code:
function url() {
var url = 'https://www.testurl.com/link1=processing';
var options = {
'method': 'get'
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}
Each run with single url shows below execution log
3:33:30 AM Notice Execution started
3:33:31 AM Info {"status":200,"message":"Import 25 of 200 completed."}
3:33:31 AM Notice Execution completed
I am looking to rerun script for first url till i get the log message containing "is not triggered" and then run second url and rerun till i get the log message containing "is not triggered" and then run third url and rerun till i get the log message containing "is not triggered" and then stop.
3:33:30 AM Notice Execution started
3:33:31 AM Info {"status":403,"message":"Import #16 is not triggered. Request skipped."}
3:33:31 AM Notice Execution completed
CodePudding user response:
There is really no way for me to test this but I think it illustrates how this can be done:
function getUrls() {
try {
var urls = [ 'https://www.testurl.com/link1=processing',
'https://www.testurl.com/link2=processing',
'https://www.testurl.com/link3=processing' ];
function getUrl(url) {
var options = { 'method': 'get' };
var response = UrlFetchApp.fetch(url, options);
while( response.message.indexOf("is not triggered") < 0 ) {
Logger.log(response);
response = UrlFetchApp.fetch(url, options);
}
}
urls.forEach( getUrl );
}
catch(err) {
Logger.log(err);
}
}