Sharepoint API CopyTo on behalf of the user not accessible

Csaba Kegl 0 Reputation points
2024-12-27T08:29:41.9166667+00:00

So I'm creating an application to manipulate Sharepoint via API, and I didn't find any solution to my problem within the documentations.

The problem is that I cannot copy a file to another existing folder with the copyTo API method, even though I can get files and upload files excellently through the Sharepoint API.
In the admin center I have set delegated AllSites.FullControl rights to my application, consented by admin.

The request I'm sending:

https://{tenant}.sharepoint.com/sites/TestSite/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/testFolder')/files('testFile.txt')/copyTo(strnewurl='/sites/TestSite/folders/Shared%20Documents/testFolder2', boverwrite=true)

Method: POST
Headers:
Authorization: Bearer {token}
Accept: application/xml

The response I get is:

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <m:code>-2147024891, System.UnauthorizedAccessException</m:code>
    <m:message xml:lang="en-EN">Access denied</m:message>
</m:error>
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,799 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,068 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.