I am trying to move a file/folder from one location to another using a REST call, but I am getting the following error:

    error: {
        code: "-1, Microsoft.SharePoint.Client.InvalidClientQueryException"
        message: "An unexpected 'EndOfInput' node was found when reading from the JSON reader. A 'StartObject' node was expected."

I can successfully run a GET request to get a file/folder, but PATCH is not working.

Here's my headers:

Authorization: Bearer eyJ0eXAiOiJKV1Q...g94tP3hkv9g
If-Match: "{8DFE1DAB-D51B-45F9-B181-E9DE3952B407},1"
Body: {"parentReference": {"id": "01J5374RUCQ5Z4U6XLMND3Q4U7GS6JURNJ"}}

And here's my endpoint:


My guess is that the Body header is wrong but I have no idea how it should look.

Any ideas?

  • OK, so I've established that the JSON needs to be in the payload rather than a body header.! Hopefully I can work the rest out from there
    – Tom
    Aug 11, 2015 at 15:17

1 Answer 1


You can use the next code:

$(function() {
            SP.SOD.executeFunc('sp.js', 'SP.ClientContext', CopyFile);

    function CopyFile(){
        var oUrl =  _spPageContextInfo.webAbsoluteUrl +"/_api/web/getfilebyserverrelativeurl('/Library/acento.txt')/copyto(strnewurl='/Lybrary_2/acento.txt',boverwrite=true)";
            url: oUrl,
            type: "POST",
            headers: {
                "Accept": "application/json; odata=verbose",
                "X-RequestDigest":  $("#__REQUESTDIGEST").val()
            success: function(data){
            error: function(data){

This code will copy the selected file the new Document Library, overwriting the files if it's exist. There is another method called MoveTo, the syntax is very similar:

/getfilebyserverrelativeurl('/Shared Documents/filename.docx')
    /moveto(newurl='/Other Folder/filename.docx',flags=1)

I hope to be helpful

  • Is it possible to move the folder in this way? My folder is having multiple folders and multiple documents inside it.
    – Mihir
    Oct 18, 2018 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.