Link to home
Start Free TrialLog in
Avatar of Michael Vasilevsky
Michael VasilevskyFlag for United States of America

asked on

REST copyTo Method in SharePoint Online

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);
  };
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Walter Curtis
Walter Curtis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. Glad you got your answer. Have a good one.