In SharePoint Online, I'm trying to move files that are in a folder in a library to another folder in another library. I'm running a console app to do this so using the API.
I'm mostly there but getting URL Length 400 error "The length of the URL for this request exceeds the configured maxUrlLength value." for some files using this query:
odataQuery = $"_api/web/GetFileByServerRelativeUrl('/{subsite}/{sourceLibrary}/{Folder}/{r.Name}')/moveto(newurl='/{subsite}/{destLibrary}/{Folder}/{r.Name}',flags=1)";
Which gives this URL:
https://organisation.sharepoint.com/sites/Dynamics365Sandbox/_api/web/GetFileByServerRelativeUrl('/sites/Dynamics365Sandbox/account/Test%20Account_231A283D5B33E811811D5065F38A4A41/some%20long%20filename.doc')/moveto(newurl='/sites/Dynamics365Sandbox/accountt/Test%20Account_231A283D5B33E811811D5065F38A4A41/some%20long%20filename.doc',flags=1)
I'm trying to find a way to do this using the UniqueId of the file but I'm unsure which part of the URL is causing the problem and how to resolve it.
I've tried this but get a malformed URL error "Bad Request":
odataQuery = $"_api/web/lists/getbytitle('{subsite}/{sourceLibrary}')/items?$select=id&$filter=Id eq '{r.UniqueId}'/moveto(newurl='/{subsite}/{destLibrary}/{Folder}/{r.Name}',flags=1)";