Can't get folder and files details using sharepoint api request getting this error

Purvesh Tejani 0 Reputation points
2023-02-10T02:43:34.24+00:00

Using this request to get all data (folder and files from SharePoint)
https://tenant.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Shared Documents')

Getting this error

{

"error": {

    "code": "-2147024891, System.UnauthorizedAccessException",

    "message": {

        "lang": "en-US",

        "value": "Attempted to perform an unauthorized operation."

    }

}

}

For every get request, we are getting this error.
We are trying to get folder and files data but we can't because of this unexpected error.
Give us any solution for this or any proper documentation about getting the folder and files data.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,426 Reputation points Microsoft External Staff
    2023-02-13T05:09:24.1966667+00:00

    Hi @Purvesh Tejani

    I found there is something missing in your url. The url should be like following. If you miss the /sites/xxxx,the api will get the library in the whole tenant, this will need global administrator

    https://tenant.sharepoint.com/sites/xxxx/_api/web/GetFolderByServerRelativeUrl('/sites/xxxx/Shared Documents')
    
    

    Please try to call the api again

    1 person found this answer helpful.

  2. RaytheonXie_MSFT 40,426 Reputation points Microsoft External Staff
    2023-02-10T06:14:47.6666667+00:00

    Hi @Purvesh Tejani

    This error means your account doesn't have the permission to the site. To retrieve folders and files you need permission to the library first. Please check permission in the url: /_layouts/15/user.aspx. If you don't have permission to the library. Please grant access in Library setting

    User's image

    And grant permission like following

    User's image


    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.


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.