I'm trying to make a copy of a MS Word document and add it to a document library in SharePoint Online with the below code, which runs once without firing the success or fail message, and throws "SP.RequestExecutor is not a constructor" on subsequent executions. I have jQuery referenced on the master page.
What am I missing?
function copy() {
var hostweburl = decodeURIComponent("https://myWeb.sharepoint.com");
var appweburl = decodeURIComponent("https://myWeb.sharepoint.com/mySite");
$.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js");
var executor = new SP.RequestExecutor(appweburl);
var url = "https://myWeb.sharepoint.com/mySite/_api/web/folders/getByUrl('mySite/Deviations/Forms/Deviations/')/Files/getByUrl('template.docx')/copyTo(strNewUrl = 'mySite/Deviations/myTestDev.docx', bOverWrite = true)";
executor.executeAsync({
url: url,
method: "POST",
binaryStringResponseBody: true,
success: successHandler,
error: errorHandler
});
function successHandler() {
console.log('success');
};
function errorHandler(errMsg) {
console.log('fail ' + errMsg);
};
}}