I'm trying to build a script to retrieve data from an API, and fill an array that i'm trying to create automatically in Google Apps Script.
When I try to construct the columns and fill each column with the value that it should get, the variable column (colonnes
) in the script turn gray ( For Information this method works when I tried it before with other APIS), so i can't modify columns of my array.
function GetAllProduct() {
var token=ConnectAlkemics();
var headers = {
"accept": "*/*",
"accept-language": "fr",
'Authorization' : 'Bearer ' token,
'cache-control': 'no-cache',
'content-type': 'application/json;charset=UTF-8',
'expires': '-1',
'pragma': 'no-cache',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'x-alk-priority': '9'
};
var options = {
'method' : "GET",
"headers" : headers
};
var source = SpreadsheetApp.getActive().getSheetByName("GTIN");
var ss = SpreadsheetApp.getActive().getSheetByName("RESULTATS");
ss.clear();
var total = 0;
var debut = 2;
var moregtin = true
var lignegtin = 1;
var colonnes = [
"GTIN",
"Libelle long",
"Libelle Court",
"Fournisseur",
"Code Tiers",
"Marque",
];
}
CodePudding user response:
Try this:
function GetAllProduct() {
var token=ConnectAlkemics();
var headers = {
"accept": "*/*",
"accept-language": "fr",
'Authorization' : 'Bearer ' token,
'cache-control': 'no-cache',
'content-type': 'application/json;charset=UTF-8',
'expires': '-1',
'pragma': 'no-cache',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'x-alk-priority': '9'
};
var options = {
'method' : "GET",
"headers" : headers
};
const ss = SpreadsheetApp.getActive()
var source = ss.getSheetByName("GTIN");
var sh = ss.getActive().getSheetByName("RESULTATS");
sh.clear();
var total = 0;
var debut = 2;
var moregtin = true
var lignegtin = 1;
var colonnes = [
"GTIN",
"Libelle long",
"Libelle Court",
"Fournisseur",
"Code Tiers",
"Marque",
];
sh.getRange(1,1,[colonnes].length,colonnes.length).setValues([colonnes]);
}