1

I have a folder in sharepoint. I wanted to move a file from one folder to another.

As per documentation, my trial was like below.

 headers = {"Authorization" : "Barer" + Token, 
            'Accept': 'application/json;odata=nometadata',
            'Content-Type': 'application/json;odata=verbose',
            'X-HTTP-Method': "POST",
            'X-RequestForceAuthentication': 'true'
            }

url = "https://sharepointDomain/sites/<app_name>/_api/web/getFileByServerRelativeUrl('/sites/SourceFoldername/test.xlsx')/moveto(newurl=/sites/DestinationFolderName/Test.xlsx',flags=1)?@target=sharepointDomain"

response = request.post(url, headers = headers)
print(response)

And the response I get is

The HTTP method 'GET' cannot be used to access the resource 'moveto'. The operation type of the resource is specified as 'Default' 

Thanks in advance.

1 Answer 1

1

The url should be like:

https://sharepointDomain/sites/<app_name>/_api/web/getFileByServerRelativeUrl('/sites/SourceFoldername/test.xlsx')/moveto(newurl='/sites/DestinationFolderName/Test.xlsx',flags=1)?@target=sharepointDomain"

My test code:

function MoveFile(){
        var oUrl =  _spPageContextInfo.webAbsoluteUrl +"/_api/web/getfilebyserverrelativeurl('/doc2/doc.docx')/moveto(newurl='/doc1/doc.docx',flags=1)";
        $.ajax({
            url: oUrl,
            type: "POST",
            headers: {
                "Accept": "application/json; odata=verbose",
                "X-RequestDigest":  $("#__REQUESTDIGEST").val()
            },
            success: function(data){
                console.log(data);
            },
            error: function(data){
                console.log(data);
            }
        });
    }

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.