user12501650
user12501650

Reputation:

JIVE API GET request returns null for values

I can't seem to access any of the values in my Jive API response. This is what I've got so far, which works. I just need to get the values, but seem to be returning null every time I try to access them. When I iterate the object, I can access the value of the allocated space, ie. single characters as opposed to the value of a key. Please help!

function include(filename) { 

var finalRequest = UrlFetchApp.fetch('https://www.cloudconnect.xxx...);

var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", 
"").trim(); 

for(i in data){
Logger.log(data); 
}
}

Upvotes: 1

Views: 93

Answers (1)

Tanaike
Tanaike

Reputation: 201513

If you want to retrieve the key and values by parsing the response value from the URL, how about the following modification?

Modified script:

function include(filename) { 
  var finalRequest = UrlFetchApp.fetch('https://www.cloudconnect.goog/api/core/v3/contents?count=5&fields=subject,content,links.next');
  var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", "").trim();

  data = JSON.parse(data); // Added
  for (var i in data) {
    Logger.log("key: %s, value: %s", i, data[i]); // Modified
  }
}
  • In your case, you can also use var data = finalRequest.getContentText().replace("throw 'allowIllegalResourceCall is false.';", "").trim(); instead of var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", "").trim();.

References:

If I misunderstood your question and this was not the direction you want, I apologize.

Upvotes: 0

Related Questions