I plan to design a workflow that move a document from main site to a subsite. But I found out that REST API moveTo/copyTo method only for within a same site.
Anyone have REST API solution ? Thank you.
FYI: I using Sharepoint designer 2013.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI plan to design a workflow that move a document from main site to a subsite. But I found out that REST API moveTo/copyTo method only for within a same site.
Anyone have REST API solution ? Thank you.
FYI: I using Sharepoint designer 2013.
Indeed, you only can copy/move files between libraries at the same level. A walk around could by using the endpoint "/openbinarystream" this will retrieve... well a little obvius what this will return. When you get the binarystrem, using "RequestExecutor" you could use a call like this
$.getScript(_spPageContextInfo.webServerRelativeUrl + "/_layouts/15/SP.RequestExecutor.js", function () {
var createitem = new SP.RequestExecutor(_spPageContextInfo.webServerRelativeUrl);
createitem.executeAsync({
url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/GetByTitle('list_template')/RootFolder/Files/add(FileName='file_name.docx', overwrite='false'))",
method: "POST",
binaryStringRequestBody: true,
body: binary, //<-- your binary
success: fsucc,
error: ferr,
state: "Insert"
});
function fsucc(data) {
console.log(data + ' uploaded successfully');
deferred.resolve(data);
}
function ferr(data) {
console.log(fileName + "not uploaded error");
deferred.reject(data);
}
});
I hope it can help you