web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Get the SharePoint Gro...
Power Apps
Unanswered

Get the SharePoint Group of a specific Document Library

(0) ShareShare
ReportReport
Posted on by 75
Apologies, but I know this must be relatively simple. I just can't seem to work it out.
 
We have over 1000 Document Libraries, and a couple of hundred SharePoint Groups. Some Document Libraries have SharePoint Groups attached to them, to manage their permissions. Most don't.
 
When I click on one of the Document Libraries in a gallery, I'd like to load up the relevant SharePoint Group (if one is attached).
 
I can load all Document Libraries, and also all SharePoint Groups, using _api calls.
 
I just can't find the relevant _api call, to see if a specific Document Library has a specific SharePoint Group that is used to manage its permissions (i.e. the mapping of Document Libraries to SharePoint Groups; or, the mapping of SharePoint Groups back to Document Libraries).
 
Grateful for any suggestions...! :-)
Categories:
I have the same question (0)
  • Suggested answer
    Robu1 Profile Picture
    1,459 Super User 2025 Season 2 on at
    Hi @gregmck, ,
     
    Thank you for choosing Microsoft Community.
     
    To find out if a specific Document Library has a SharePoint Group attached to it for managing permissions, you can use the SharePoint REST API. 
     
    Here's a step-by-step guide:
     
    Get the Document Library: First, you need to get the Document Library by its server-relative URL. You can use the following API call:
    GET https://{site_url}/_api/web/GetFolderByServerRelativeUrl('{library_relative_url}')
    This will give you the properties of the Document Library.
     
    Check Permissions: Next, you need to check the permissions of the Document Library. You can use the following API call:
    GET https://{site_url}/_api/web/GetFolderByServerRelativeUrl('{library_relative_url}')/ListItemAllFields/RoleAssignments 
    This will return the role assignments for the Document Library, including the SharePoint Groups that have permissions.
     
    Get SharePoint Groups: To get the details of the SharePoint Groups, you can use the following API call:
    GET https://{site_url}/_api/web/roleassignments/getbyprincipalid({principal_id})/roledefinitionbindings
    Replace {principal_id} with the ID of the SharePoint Group you got from the previous call.
     
    By following these steps, you should be able to map Document Libraries to SharePoint Groups and vice versa.
     
    If you need more detailed information, you can refer to the Microsoft documentation- Working with folders and files with REST | Microsoft Learn
     
    I hope these steps help resolve the issue! If you need more specific guidance, feel free to ask.
    If this fixes the issue, please mark as resolved to help others with find it.
     
    Happy to help 
     
    Robu 1
  • gregmck Profile Picture
    75 on at
    Hello Robu 1,
     
    Thank you very much for the response, which is appreciated. :-)
     
    On the face of it, it looked promising.
     
    I've never had any problem mapping Domain Groups to SharePoint Groups, but I'm still having issues mapping SharePoint Groups to Document Libraries (which you'd think would actually be simpler?!)
     
    I have followed through the instructions, but I seem to be failing at the second step.
     
    With a Document Library named, for example, Test Library LTD (inheritance broken, SharePoint Group deployed), the first step
     
    _api/web/GetFolderByServerRelativeUrl('{library_relative_url}')
     
    returns (reduced)

        "body": {
            "d": {
                "Files":
                "ListItemAllFields":
                "ParentFolder"
                "Properties"
                "StorageMetrics"
                "Folders"
                "Exists": true,
                "ExistsAllowThrowForPolicyFailures": true,
                "ExistsWithException": true,
                "IsWOPIEnabled": false,
                "ItemCount": 59,
                "Name": "TestLibraryLTD",
                "ProgID": null,
                "ServerRelativeUrl": "/teams/300862/TestLibraryLTD",
                "TimeCreated": "2021-10-06T13:29:48Z",
                "TimeLastModified": "2024-11-26T14:16:46Z",
                "UniqueId": "664df9e4-e77e-4877-912a-43e7a1f52722",
                "WelcomePage": ""
            }
        }
    }
     
    but drilling into the /ListItemAllFields returns:
     
    <d:ListItemAllFields xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:null="true"/>
     
    where the response is "null".
     
    I've found a workaround, that seems to work in most cases:
     
    _api/web/lists/GetByID('9be82e50-92f2-45eb-80e7-62e2ac6bb0ba')/RoleAssignments
     
    where GetByID is the ID of the Document Library.
     
    This returns the Principal ID in the results (reduced):
     
    "results": [
          {
            "__metadata"
            "Member"
            "RoleDefinitionBindings"
            "PrincipalId"3
          }​​​​​​​ 
  • Robu1 Profile Picture
    1,459 Super User 2025 Season 2 on at
    Glad you found a work around this issue gregmck
     
    You are right on track with your workaround.
     
    The issue with the /ListItemAllFields returning null might be due to the specific configuration or permissions of the Document Library.
     
    Your workaround using _api/web/lists/GetByID('{library_id}')/RoleAssignments to get the Principal ID is a good approach. Once you have the Principal ID, you can use it to get the details of the SharePoint Group.
     
    Here’s a refined step-by-step process based on your workaround:
     
    Get the Document Library by ID:
    GET https://{site_url}/_api/web/lists/GetByID('{library_id}')

    Get Role Assignments:
    GET https://{site_url}/_api/web/lists/GetByID('{library_id}')/RoleAssignments
    This will return the Principal ID of the SharePoint Group.
     
    Get SharePoint Group Details:
    GET https://{site_url}_api/web/roleassignments/getbyprincipalid({principal_id})/roledefinitionbindings
    Replace {principal_id} with the ID you got from the previous call.
     
    By following these steps, you should be able to map Document Libraries to SharePoint Groups effectively. If you encounter any specific errors or issues, feel free to share them, and I'll do my best to assist you further. 😊
     
    Keep up the great work!
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard