Skip to content

Instantly share code, notes, and snippets.

@tanyagupta
Last active January 2, 2017 19:27
Show Gist options
  • Save tanyagupta/6fd0fd25ef0907dee2af82486fd270c3 to your computer and use it in GitHub Desktop.
Save tanyagupta/6fd0fd25ef0907dee2af82486fd270c3 to your computer and use it in GitHub Desktop.
UrlFetchApp script with Zendesk (multiple pages)
function zd_get (cmd) {
var url = ZD_BASE+cmd;
var results =[];
var service = getService();
if (service.hasAccess()) {
do {
try {
var response = UrlFetchApp.fetch(url, {headers: {'Authorization': 'Bearer ' + service.getAccessToken(),}});
}
catch (e) {
return e;
}
var result = JSON.parse(response.getContentText());
results.push(result);
url = result['next_page'];
Utilities.sleep(250); // give the server a break
} while (result['next_page'] !=null);
return results;
}
else return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment