I'm doing a request to an API that is successful but i need to get the data of the array returned, below i will put how the array looks like so you can help me to extract the data
{ total_grand: 30600000,
total_billable: null,
total_currencies: [ { currency: null, amount: null } ],
total_count: 5,
per_page: 50,
data:
[ { id: 13998122,
pid: 1570982183,
tid: null,
uid: 5386231,
description: 'Finish the first part of the RCP mockup',
start: '2020-03-26T13:00:00-04:00',
end: '2020-03-26T16:00:00-04:00',
updated: '2020-04-02T13:25:15-04:00',
dur: 10800000,
user: 'Jose',
use_stop: true,
client: 'PLA',
project: 'Training',
project_color: '0',
project_hex_color: '#3750b5',
task: null,
billable: null,
is_billable: false,
cur: null,
tags: []
} ]
}
I want to access to the user,project,tags,client,start,end and description so i can put it in my SpreadSheet. How can i do that?
This is how i do the request and how i try to access to the data in the array in my variable togglData
for (var i = 0; i < projects.length; i++) {
var listProjects = projects[i];
var reportURL = baseURL + '/reports/api/v2/details' + params;
var reportFetch = UrlFetchApp.fetch(reportURL, options);
var togglReport = JSON.parse(reportFetch.getContentText());
var togglData = togglReport["data"]["user"];
Logger.log(togglReport);
}
console.log(togglReport)orconsole.log(JSON.stringify(togglReport))instead. Logger doesn't provide accurate logs(=is not valid json; strings should be quoted). 2. Make sure your json is valid. You can hide sensitive details by changing them instead of adding.... 3. Is there anything you've tried to mould the data to a 2D array, the format required by Google sheets'setValues?console.loghas been supported in apps script for years now.console.lognever printed anything when i put in my scripts so i don't know if i need to do something else to make it work, that's why when i'm programming in GAS i avoid theconsole.login my scripts and useLogger.loginstead @TheMaster