Здравствуйте.
Пытаюсь вставить массив в таблицу. Вот код.
async function CitiesNovaPoshta2 () {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Города");
let x = 0;
var payload = {
'apiKey': '6bde07fde09a9f1d11b034df69403d73',
'modelName': 'Address',
'calledMethod': 'getCities',
}
var options = {
'method' : 'post',
'headers': {
'content-type': 'application/json',
},
'payload': JSON.stringify(payload),
};
while (x < 10) {
var result = await UrlFetchApp.fetch('https://api.novaposhta.ua/v2.0/json/', options);
if (result) {break;}
x++
};
var dataCities = JSON.parse(result.getContentText());
//var orderList1 = JSON.stringify(dataCities, null, 2);
//Logger.log(orderList1);
const lengthCities = dataCities["data"].length;
//lr = sheet.getLastRow()-1;
let array = [];
for (let i = 0; i < lengthCities; i += 10) {
for (let j= i; j<i+10; j++){
let buffer = [];
buffer.push(dataCities["data"][j]["Description"]);
buffer.push(dataCities["data"][j]["DescriptionRu"]);
buffer.push(dataCities["data"][j]["Ref"]);
buffer.push(dataCities["data"][j]["Delivery1"]);
buffer.push(dataCities["data"][j]["Delivery2"]);
buffer.push(dataCities["data"][j]["Delivery3"]);
buffer.push(dataCities["data"][j]["Delivery4"]);
buffer.push(dataCities["data"][j]["Delivery5"]);
buffer.push(dataCities["data"][j]["Delivery6"]);
buffer.push(dataCities["data"][j]["Delivery7"]);
buffer.push(dataCities["data"][j]["Area"]);
buffer.push(dataCities["data"][j]["SettlementType"]);
buffer.push(dataCities["data"][j]["IsBranch"]);
buffer.push(dataCities["data"][j]["PreventEntryNewStreetsUser"]);
buffer.push(dataCities["data"][j]["Conglomerates"])
buffer.push(dataCities["data"][j]["CityID"]);
buffer.push(dataCities["data"][j]["SettlementTypeDescription"]);
buffer.push(dataCities["data"][j]["SettlementTypeDescriptionRu"]);
buffer.push(dataCities["data"][j]["SpecialCashCheck"]);
buffer.push(dataCities["data"][j]["Postomat"]);
buffer.push(dataCities["data"][j]["AreaDescription"]);
buffer.push(dataCities["data"][j]["AreaDescriptionRu"]);
array.push(buffer);
}
sheet.getRange(sheet.getLastRow() + 1,1,array.length, array[0].length).setValues(array);
// SpreadsheetApp.flush()
}
}
Не ругается. Но и не вставляет. Что я делаю не так? Как правильно добавить массив в таблицу? Помогите кто может.