I call the api to search into the json based on skus ,the user will put the sku and the start time ,dthen the function will bee count how many orders we have for this sku on this day
This is my code:
// to call the page
function firstCall(pag,start){
try{
var url ='https://*****************************?Page=' + pag + '&shopId%5B%5D=90841&pageSize=250' + '&' + 'minOrderDate='+ start;
var res =UrlFetchApp.fetch(url);
var content = res.getContentText();
var json= JSON.parse(content);
var node = json.data;
return node;
}
catch(err){
return "Error getting data" + err;
}
}
//to count how many order per day and per sku
function getInven3(sKu,start){
if(start == "") return "!";
start ="2021-11-17T";
try{
var url ='https://*********************************?shopId%5B%5D=90841&pageSize=250' + '&' + 'minOrderDate='+ start;
var res = UrlFetchApp.fetch(url);
var content = res.getContentText();
var json = JSON.parse(content);
var count =0 ;
var count_tow =0 ;
if (json.paging.TotalPages===1){
for (var i=0; i<firstCall(1,start).length; i++) {
if(firstCall(1,start)[i].state == 7){
for (var j=0; j<firstCall(1,start)[i].orderItems.length; j++) {
var node3=firstCall(1,start)[i].orderItems[j].product.sku;
if ((node3 == sKu)) {
count++;
}
}
}
}
return count;
}
else if (json.paging.TotalPages>1)
{
console.log("2 page");
var d=0;
for (var x = 0, ln = json.paging.TotalPages; x < ln; x++) {
d++;
if(d<=json.paging.TotalPages){
for (var i=0; i<firstCall(d,start).length; i++) {
if(firstCall(d,start)[i].state == 7){
for (var j=0; j<firstCall(d,start)[i].orderItems.length; j++) {
var node3=firstCall(d,start)[i].orderItems[j].product.sku;
if ((node3 == sKu)) {
count_tow++;
}
}
}
}
}
}
return count_tow;
}
}
catch(err){
return "Error getting data" + err;
}
}
Error messages keep saying “Exceeded maximum execution time (line 0).”
Could anyone help? Thank you a lot!