Web Activity to call Sharepoint REST API copyTo Method

Leau Bee Lin 86 Reputation points
2021-10-20T06:57:26.777+00:00

1) Web Activity "GetBearerToken" to get authorization (bearer) token is working
2) After the above, create another Web Activity "CopyTo" to copy file in SharePoint document library is as below.

URL=
https://{Site Url}/_api/web/GetFileByServerRelativeUrl('/sites/TestSite/Shared%20Documents/test.xlsx')/copyTo(strNewUrl='/sites/TestSite/Shared%20Documents/testCopy.xlsx',bOverWrite=true)

Method = POST

Headers
Authorization=@{concat('Bearer ', activity('GetBearerToken').output.access_token)}
Accept=application/json

It is giving error : {"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Not well formatted JSON stream."}}}

Please advise what is missing.

3) Is there a limitation on the length of REST API URL? 299?

Thanks in advance.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
6,305 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
1,686 questions
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 14,386 Reputation points Microsoft Employee
    2021-10-21T02:10:47.497+00:00

    Hi @Leau Bee Lin ,
    Per my test, I can get Access Token without grant permission to the client id. So I will agree with ShaikMaheer's opinion. Please check if you have grant permission to the client id. You can refer to following steps:
    Go to the appinv.aspx page by the url

    https://xxx.sharepoint.com/sites/test/_layouts/15/appinv.aspx  
    

    Fill the client id and click look up and App's Permission Request XML like the pic

    142291-image.png

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

    You can choose permission level by following link
    https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint

    Click create and then trust it
    142302-image.png
    The document for reference
    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs

    Finally the maximum length of the Request URI for requests to our REST API endpoints is 4096 characters. If the request URI exceeds this length, you should see the following error message in the response:

    URI length exceeds the configured limit of 4096 characters  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



1 additional answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 28,106 Reputation points Microsoft Employee
    2021-10-20T11:53:44.1+00:00

    Hi @Leau Bee Lin ,

    From the error messages it seems its related to access issue.

    May be the authentication which you are using is not having access on API. Could you please try to use your token via postman or other third party API request services and see is it working there?