I am working on getting total time entries from via external API. The function needs to get user data which includes id saved in an array. This ID needs to be called by the second function to get hours for a data range and total them up and also save them in an array. The Systems API is in https://github.com/10Kft/10kft-api
This my first function to get user data.
function get_users() {
// function loops through 10000ft paginations and scrapes user data to array
var userarray = [];
var lastpage = false;
var page = 1;
do{
// gets 10kft data
var users = read10k_users(page);
// writes data from current page to array
for (i in users.data) {
var rec = {};
// pushing of mandatory data
rec.id = users.data[i].id;
rec.display_name = users.data[i].display_name;
rec.email = users.data[i].email;
userarray.push(rec);
}
Logger.log(userarray)
// checks if this is the last page (indicated by paging next page link beeing null
if (users.paging.next != null) {
lastpage = false;
var page = page + 1;
} else {
lastpage = true;
}
}while (lastpage == false);
return (userarray);
}
My second function needs to reference id saved in the array in order to return total hours for specific users and this is where am lost.
function get_timedata(id) {
// function loops through 10000ft paginations and scrapes time entries to array
var timearray = [];
var lastpage = false;
var page = 1;
do{
// gets time data from 10000ft
var timedata = read10k_timedata(from_dt,to_dt,);
// writes data from current page to array
for (i in timedata.data) {
var rec = {};
// collection of time data from time entries endpoint
rec.id = timedata.data[i].id;
rec.user = timedata.data[i].user_id;
rec.hours_inc = timedata.data[i].hours;
// pushing incurred hours
if (rec.hours_inc >= 0 ) {
timearray.push(rec);
}
//Logger.log(timearray)
}
// checks if this is the last page (indicated by paging next page link beeing null
if (timedata.paging.next != null) {
lastpage = false;
var page = page + 1;
} else {
lastpage = true;
}
}while (lastpage == false);
return (timearray);
}
Any help would be much appreciated. Thanks in advance