Tuesday, December 28, 2021

Get User Permissions From SharePoint Group In PowerApps: Part 3

Hello Friends.

Welcome back in the User Permissions series. In last post, we had created a Power Automate Instant cloud flow of PowerApps type. Added 2 input variables that will connect with PowerApps to provide the user email and list name. Then we have added few additional variables that will be used during the flow. Links of past 2 posts are-

  1. Get User Permissions From SharePoint Group In PowerApps: Part 1
  2. Get User Permissions From SharePoint Group In PowerApps: Part 2
In this post, we will use HTTP request to get the RoleAssignments (SharePoint Groups permission upon the list) and then we will use Parse JSON to parse the output of HTTP request so that it can use further. Continuing from last post-
  1. Click on "+ New step" to add an action. Search for HTTP. A list of HTTP actions will get displayed. From this, choose "Send an HTTP request to SharePoint".
  2. Rename the Title as "HTTP Role Assignments"
    1. Site Address: select the site url
    2. Method: GET
    3. Uri: _api/Web/Lists/GetByTitle('@{outputs('Compose_ListName')}')/RoleAssignments
  3. Save the flow. Now, before we parse the JSON, we need the output of above HTTP request. Therefore, we need to execute this flow. For this, there is a link "Test" on top just next to Save|Flow checker links. Click on that Test link.
  4. Choose Manually. Click on Test button appeared at bottom.
  5. It will show the connection you need to provide access. Click on Continue.
  6. The moment, you click on Continue, it will show you 2 input boxes to provide the Email and List name and then click on Run flow
  7. Now click on Done.
  8. Wow! The flow executed successsfully.
  9. Expand the last action "HTTP Role Assignments" and the click on "Show raw outputs".
  10. It will show the output in right side pane. scroll a little bit down, You will find the output something like below-
  11. "body": {
            "d": {
                "results": [
                    {
                        "__metadata": {
                            "id": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(3)",
                            "uri": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(3)",
                            "type": "SP.RoleAssignment"
                        },
                        "Member": {
                            "__deferred": {
                                "uri": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(3)/Member"
                            }
                        },
                        "RoleDefinitionBindings": {
                            "__deferred": {
                                "uri": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(3)/RoleDefinitionBindings"
                            }
                        },
                        "PrincipalId": 3
                    },
                    {
                        "__metadata": {
                            "id": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(4)",
                            "uri": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(4)",
                            "type": "SP.RoleAssignment"
                        },
                        "Member": {
                            "__deferred": {
                                "uri": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(4)/Member"
                            }
                        },
                        "RoleDefinitionBindings": {
                            "__deferred": {
                                "uri": "https://XXXX.sharepoint.com/sites/YYYY/_api/Web/Lists(guid'b59b53f4-abc9-4871-9509-8fd9956f91fa')/RoleAssignments/GetByPrincipalId(4)/RoleDefinitionBindings"
                            }
                        },
                        "PrincipalId": 4
                    }
                ]
            }
        }
    
  12. Copy the highlighted section and paste in Notepad. Now close this output pane and then click on Edit link given at top right to edit the flow.
  13. Add a new step at the last "Parse JSON".
  14. Add below code in Content box-
    1. body('HTTP_Role_Assignments')?['d']?['results']
      
  15. For Schema, click on "Generate from sample". A new popup will open. In this popup, paste the output content we had copied in Notepad and then click on Done. Power Automate, will automatically generate schema from this output.
  16. This way, we had fetched the permissions applied upon list and then we parsed it in JSON.
  17. Save the flow.
  18. This completes the Part 3. In Part 4, we will apply for each loop upon this result and will implement the final process.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.