I have two functions.
One queries for project id, project name, and project status and saves them up in an array.This works fine.
function get_All_Projects() {
var options = {
method: "get",
headers: {
Authorization: "Bearer " + tkft_token
}
};
var url = tkft_url + endpoint + "auth=" + tkft_token + pages;
var response = UrlFetchApp.fetch(url, options);
var info = JSON.parse(response);
var content = info.data;
var project_arr = [];
var identity = {};
for (var i = 0; i < content.length; i++) {
if (content.length > 0) {
identity.Project_ID = content[i].id;
identity.Project_Name = content[i].name;
identity.Project_Start_Date = content[i].starts_at;
identity.Project_End_Date = content[i].ends_at;
identity.Project_Status = content[i].project_state;
project_arr.push(identity);
}
}
//Logger.log(project_arr);
}
The second function is supposed to use the Id saved up in the project_arr so that I can get all users per project. The challenge is, I am having a hard time including one of the array objects in the URL for this function and also looping through every project id. I keep running into Cannot read property 'length' of undefined error, Is there something I am missing?
function get_By_Users(project_arr) {
var options = {
method: 'get',
headers: {
Authorization: 'Bearer ' + tkft_token
}
};
for (var i = 0; i<project_arr.length; i++) {
var url = tkft_url+ 'projects/'+ project_arr.Project_ID +'/users?auth='+ tkft_token + pages
var response = UrlFetchApp.fetch(url,options);
var info= JSON.parse(response);
var content = info.data;
}
Logger.log(content);
}
get_By_Users()?get_By_Users()outside of yourget_All_Projects()function,project_arris undefined since it is a local var.