I've been working on fetching JSON data from my API to import it into Google Sheets using Google Apps Script. Everything is running smoothly, except for one issue - when I try to map the object, the resulting array contains undefined objects.
Here's the snippet of my script:
function GETMYJSONDATA() {
var options = {
"method" : "get",
"headers" : {
"Authorization": "Bearer REDACTED"
}
};
const url = "REDACTED"
const res = UrlFetchApp.fetch(url, options)
const dataAsText = res.getContentText()
const data = JSON.parse(dataAsText)
const results = data.response.users.map (user => {
return
[user["department_text"]]
})
return results
}
Here you can see the raw JSON response from my API and also the result from the Apps Script debugger: