Last active
January 2, 2017 19:27
-
-
Save tanyagupta/6fd0fd25ef0907dee2af82486fd270c3 to your computer and use it in GitHub Desktop.
UrlFetchApp script with Zendesk (multiple pages)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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