Skip to main content

Notifications

Power Automate - General Discussion
Unanswered

Automate M365 group membership

(0) ShareShare
ReportReport
Posted on by 5

Hi There,

 

I'd like to see if I can use Power Automate to automate the process of adding a user to a group after the group owner approves it.

 

This refers to M365 groups, Teams and distribution lists.

 

So a user would, say, complete a form to become a member of an existing M365 group, team or distribution list, the automation then checks that group and send an approval to it's owners to approve. Once approves, it adds the member to group/team/dl.

 

Is this possible?

 

Thanks,

  • VictorIvanidze Profile Picture
    VictorIvanidze 11,853 on at
    Re: Automate M365 group membership

    Hi @QduBruyn,

    the GRAPH request cannot find '(Int) - Group IT Members' group.

    Are you sure such group exists? 

  • QduBruyn Profile Picture
    QduBruyn 5 on at
    Re: Automate M365 group membership

    Hi Expiscornovus,

     

    Here you go:

    QduBruyn_2-1648556301675.png

    {
        "host": {
            "connectionReferenceName""shared_office365groups",
            "operationId""HttpRequest"
        },
        "parameters": {
            "Uri""https://graph.microsoft.com/v1.0/groups/?$filter=displayName eq '(Int) - Group IT Members'&$expand=owners($select=mail)",
            "Method""GET",
            "ContentType""application/json"
        }
    {
        "statusCode"200,
        "headers": {
            "Transfer-Encoding""chunked",
            "Vary""Accept-Encoding",
            "Strict-Transport-Security""max-age=31536000",
            "request-id""55f193f8-92da-4746-b194-21dd1a91914c",
            "client-request-id""55f193f8-92da-4746-b194-21dd1a91914c",
            "x-ms-ags-diagnostic""{\"ServerInfo\":{\"DataCenter\":\"France Central\",\"Slice\":\"E\",\"Ring\":\"5\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"PA1PEPF0004F032\"}}",
            "x-ms-resource-unit""2",
            "OData-Version""4.0",
            "Timing-Allow-Origin""*",
            "x-ms-apihub-cached-response""false",
            "x-ms-apihub-obo""true",
            "Cache-Control""no-cache",
            "Date""Mon, 28 Mar 2022 13:44:20 GMT",
            "Content-Type""application/json",
            "Content-Length""95"
        },
        "body": {
            "value": []
        }
     
     

     

     

  • stayinginsync Profile Picture
    stayinginsync 139 on at
    Re: Automate M365 group membership

    @QduBruyn 

     

    UPDATE - IGNORE THIS.  It works now.

     

    I took a different approach, but this is specifically for when a new Team is created and curious as to your thoughts.

     

    First, if I manually run this Flow, without any additional work, it works just fine.  It will add all the Owners from an existing group as an Owners of a newly created Team:

     

    Screen Shot 2022-03-27 at 2.17.45 PM.png

    stayinginsync_0-1648483934645.png

     

    BUT, if I make 2 small changes, it no longer works.  First, instead of having a manual trigger, it is triggered by a new item being added to SharePoint, and the other is the approval.  Note, the "Get HTTP Request & Parse JSON are the same actions in both flows.

     

    stayinginsync_1-1648484196464.png

     

    stayinginsync_2-1648484271585.png

     

    Except now I'm getting - Action 'Send_an_HTTP_request' failed

     

     

     

    Resource 'GroupID' does not exist or one of its queried reference-property objects are not present.

     

     

     

  • Expiscornovus Profile Picture
    Expiscornovus 31,104 on at
    Re: Automate M365 group membership

    Hi @QduBruyn,

     

    The error suggests it cannot find the mail value because it did not find any group. Can you share a screenshot of your failed flow run and specifically the Send an HTTP request action (expanded to show the input/output sections)?

  • QduBruyn Profile Picture
    QduBruyn 5 on at
    Re: Automate M365 group membership

    Hi There,

     

    Thanks for your reply, I tried it.

     

    First the Send an Http request didn't work, but tried again then that part worked.

     

    Then on the Start and wait for approval, with your string, I keep getting the following:

     

    InvalidTemplate. Unable to process template language expressions in action 'Start_and_wait_for_an_approval' inputs at line '0' and column '0': 'The template language expression 'body('Send_an_HTTP_request')['value'][0]['owners'][0]['mail']' cannot be evaluated because array index '0' cannot be selected from empty array. Please see https://aka.ms/logicexpressions for usage details.'.

     

    Any idea why that may be? I copied it excatly as you said and the previous step was successful?

     

    Thanks,

  • Expiscornovus Profile Picture
    Expiscornovus 31,104 on at
    Re: Automate M365 group membership

    Hi @QduBruyn,

     

    Yes, I think this would be possible. You could use the Graph API to filter for the correct group and retrieve the owners. After that you could start and approval and wait for the outcome. If that equals approve you could add the member.

     

    Below is an example of that approach.

    This is a basic setup. You might want to check if the Send an HTTP request results are not empty for example. Additionally this current example only uses the first owner listed, you might want to change that as well.

     

    Uri for the Send an HTTP request action:

    https://graph.microsoft.com/v1.0/groups/?$filter=displayName eq '@{outputs('Get_response_details')?['body/r15d7725d8635470fbafe790d5a824af5']}'&$expand=owners($select=mail)

     

    Expression used in the Assigned To field of the Start and wait for approval action:

    body('Send_an_HTTP_request')['value'][0]['owners'][0]['mail']

     

    Expression used in the Group Id field of the Add member to Group action:

    body('Send_an_HTTP_request')['value'][0]['id']

     

    approvalformembershipgroup.png

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,475

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,767

Leaderboard