UnauthorizedAccessException while copying file to sharepoint using rest api post method in Web Activity of Azure Data Factory

Sujith S 20 Reputation points
2023-03-18T17:25:57.9+00:00

0

I have a requirement to extract data from SharePoint URL (folder:/input/current) to ADLS and once the file is loaded into ADLS,I need to archive the file into the archive folder (folder:/input/archive) in the SharePoint URL.

Here is what I tried. As per the Microsoft documentation (https://learn.microsoft.com/en-au/azure/data-factory/connector-sharepoint-online-list?tabs=data-factory#copy-file-from-sharepoint-online), I registered the application with Microsoft Identity Platform and Grant ed SharePoint Online site permission to the registered application.

I am successful till the step of extracting file from SharePoint to ADLS. But I am stuck at the step where I need to archive(move or copy) the file to different folder in SharePoint. I created a web activity and gave the following inputs

  1. URL :https://sharepoint_url/_api/web/GetFileByServerRelativeUrl('file path')/copyTo(strNewUrl='new file path',bOverWrite=true)
  2. Body :{}
  3. Headers a. Accept :application/json;odata=verbose b. Content-Type: application/json;odata=verbose c. Authorisation :@{concat('Bearer ', activity('GetBearerToken').output.access_token)}

I am getting an error

System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically"

Any Help would be highly appreciated

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,196 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
0 comments No comments
{count} votes

Accepted answer
  1. ShaikMaheer-MSFT 38,401 Reputation points Microsoft Employee
    2023-03-21T10:22:25.9866667+00:00

    Hi Sujith S,

    Thank you for posting query in Microsoft Q&A Platform.

    In this documentation), which you referred, we are only granting read permissions and in your requirement, you are trying to move or copy file to different location, it needs write permissions. Since you don't gave write permissions, it is failing it.

    Kindly give write permissions also and try again. Below is example code to use to give read and write permissions.

    <AppPermissionRequests AllowAppOnlyPolicy="true">
        <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read"/>
        <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Write"/>
    </AppPermissionRequests>
    
    

    Hope this helps. Please let me know how it goes.


    Please consider hitting Accept Answer button. Accepted answers help community as well.


0 additional answers

Sort by: Most helpful