question

LeauBeeLin-2133 avatar image
0 Votes"
LeauBeeLin-2133 asked LeauBeeLin-2133 commented

Web Activity to call Sharepoint REST API copyTo Method

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-factorysharepoint-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Amendment to the error. It should be
{"odata.error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied."}}}

0 Votes 0 ·
RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered LeauBeeLin-2133 commented

Hi @LeauBeeLin-2133 ,
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://docs.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://docs.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.





image.png (45.6 KiB)
image.png (19.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi RaytheonXie,

Token only has read permission previously. Granted write permission and it is working now.
Thanks much for all the details with screenshots.

0 Votes 0 ·
ShaikMaheer-MSFT avatar image
0 Votes"
ShaikMaheer-MSFT answered

Hi @LeauBeeLin-2133 ,

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?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi ShaikMaheer,
You are right, token only has read permission. Grant the write permission and issue resolved.
Thanks. :)

0 Votes 0 ·