Currently, I am developing a function that aims to retrieve total time entries from an external API. The primary task of this function is to fetch user data containing the id
stored in an array. Subsequently, the retrieved ID must be utilized by a secondary function to accumulate and store the total hours for a specific data range into another array. You can find the Systems API at https://github.com/10Kft/10kft-api
This is my initial function responsible for retrieving user data:
function get_users() {
// This function iterates through 10000ft paginations to gather user data into an array
var userarray = [];
var lastpage = false;
var page = 1;
do{
// Fetches data from 10kft
var users = read10k_users(page);
// Writes data from current page to the array
for (i in users.data) {
var rec = {};
// Pushing 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 being null)
if (users.paging.next != null) {
lastpage = false;
var page = page + 1;
} else {
lastpage = true;
}
}while (lastpage == false);
return (userarray);
}
The second function is supposed to utilize the saved ids in the array to calculate the total hours for specific users, but I'm facing some challenges in implementing it.
function get_timedata(id) {
// This function loops through 10000ft paginations to scrape time entries into an array
var timearray = [];
var lastpage = false;
var page = 1;
do{
// Retrieves time data from 10kft
var timedata = read10k_timedata(from_dt,to_dt,);
// Writes data from the current page to the array
for (i in timedata.data) {
var rec = {};
// Collects 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;
// Adds incurred hours to the array
if (rec.hours_inc >= 0 ) {
timearray.push(rec);
}
//Logger.log(timearray)
}
// Checks if this is the last page (indicated by paging next page link being null)
if (timedata.paging.next != null) {
lastpage = false;
var page = page + 1;
} else {
lastpage = true;
}
}while (lastpage == false);
return (timearray);
}
I would greatly appreciate any assistance or guidance on how to proceed with solving this issue. Thank you in advance!