I am learning how to make API requests using Javascript.
I have made a GET request and got the following data and I would like to loop through them to get only id, display_name and email. This are to be stored in arrays. How do I complete the javascript code?
"data": [
{
"id": 222226,
"display_name": "jane Doe",
"email": "janeDoe@testmail.com",
},
{
"id": 1111226,
"display_name": "james",
"email": "james@testmail.com",
},
{
"id": 11126,
"display_name": "Travis Mc",
"email": "travis@testmail.com",
},
Heres is my javascript code.
var options = {
method: 'get',
headers: {
Authorization: 'Bearer ' + auth
}
};
var response= UrlFetchApp.fetch(url, options);
var data = JSON.parse(response.getContentText());
I am not sure I am doing this loop part right.
for (var i = 0; i < data.length; i++) {
Logger.log(data[i].display_name);
}