Created
May 15, 2019 18:58
-
-
Save phette23/f79329a23f9e86f768310f5ea2e7faed to your computer and use it in GitHub Desktop.
custom function for Google Sheets to return data from VAULT (openEQUELLA) search API
This file contains 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
// custom function for Google Sheets | |
// usage: TRANSPOSE(VAULTSEARCH("Student, Name")) returns data from Supplemental Portfolio Review collection | |
function VAULTSEARCH(query) { | |
var token = '...', // oauth access token | |
opts = { | |
contentType: 'application/json', | |
headers: { 'X-Authorization': 'access_token=' + token } | |
}, | |
data = UrlFetchApp.fetch('https://vault.cca.edu/api/search/?collections=3eaf9745-e7d4-4cf6-be07-44691daa4714&order=modified&info=metadata,detail&q=' + encodeURIComponent(query), opts), | |
results = JSON.parse(data).results, | |
item = results[0], | |
major_re = /<major>(.*)<\/major>/, | |
cca_id_re= /<ccaAffiliated>(.*)<\/ccaAffiliated>/; | |
if (item) { | |
major = item.metadata.match(major_re) && item.metadata.match(major_re)[1] | |
cca_id = item.metadata.match(cca_id_re) && item.metadata.match(cca_id_re)[1] | |
return [item.owner.id, cca_id, major, item.modifiedDate, item.links.view] | |
} | |
return '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment