Skip to content

Instantly share code, notes, and snippets.

@trevordixon
Created July 3, 2016 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevordixon/ef7bfd27cdba87402256ed078636c77d to your computer and use it in GitHub Desktop.
Save trevordixon/ef7bfd27cdba87402256ed078636c77d to your computer and use it in GitHub Desktop.
Make signed-in requests to LDS.org from Google Apps Scripts
function example() {
// This cookie is good for many subsequent requests (until it expires)
var cookie = getCookie('[username]', '[password]');
var response = ldsGet(cookie, 'https://www.lds.org/mobiledirectory/services/v2/ldstools/current-user-detail');
Logger.log(response.getContentText());
}
function getCookie(username, password) {
var response = UrlFetchApp.fetch('https://signin.lds.org/login.html', {
method: 'post',
payload: {username: username, password: password},
followRedirects: false,
});
var cookieHeader = response.getAllHeaders()['Set-Cookie'][0];
var cookie = decodeURIComponent(cookieHeader.match(/ObSSOCookie=([^;]+)/)[1]);
return cookie;
}
function ldsGet(cookie, url) {
return UrlFetchApp.fetch(url, {
headers: {
'Cookie': 'ObSSOCookie=' + encodeURIComponent(cookie),
},
});
}
@wrightleft
Copy link

Thanks this helped me out quite a bit. I'm pulling in the member list into a spreadsheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment