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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get user Team Membership
Power Automate
Answered

Get user Team Membership

(0) ShareShare
ReportReport
Posted on by 21

Afternoon all. I was wondering if someone could help.

I am trying to get ALL teams a user is a member of and their membership role (owner or member).

At the moment, I am using 2 different Graph API calls

 

Owner
https://graph.microsoft.com/v1.0/users/{0}/ownedObjects

Member
https://graph.microsoft.com/v1.0/users/{0}/memberOf

 

Using the above solution I get 2 json objects.

 

I have used Select to create the following for ownership

 

{
 "body": [
 {
 "id": "1645466-et65-5h556-5645-45645646456",
 "displayName": "SZ BMW",
 "role": "owner"
 },
 {
 "id": "123456-et65-5hh6-45645-45645646456",
 "displayName": "NR Jon Snow",
 "role": "owner"
 }
 ]
}

 

... and for member

 

{
 "body": [
 {
 "id": "1645466-et65-5h556-5645-45645646456",
 "displayName": "SZ BMW",
 "role": "member"
 },
 {
 "id": "567567-et65-5666-4665-456477777456",
 "displayName": "UK Members Only",
 "role": "member"
 },
 {
 "id": "123456-et65-5hh6-45645-45645646456",
 "displayName": "NR Jon Snow",
 "role": "member"
 }
 ]
}

 

 

Based on the above, I am trying to create a joined list which shows their owner status and if an item in the member does not exist in owners, add it as below

 

 

{
 "body": [
 {
 "id": "1645466-et65-5h556-5645-45645646456",
 "displayName": "SZ BMW",
 "role": "owner" <=============
 },
 {
 "id": "567567-et65-5666-4665-456477777456",
 "displayName": "UK Members Only",
 "role": "member" <=============
 },
 {
 "id": "123456-et65-5hh6-45645-45645646456",
 "displayName": "NR Jon Snow",
 "role": "owner" <=============
 }
 ]
}

 

 

So I have 2 questions.

 

1. Is there another, easier way to recreate the above?

2. Could someone help me with the filter/join based on the above?

 

Thank you in advance

Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,844 Most Valuable Professional on at

    Hi @jimbobuk,

     

    With the current setup you could use an array variable and append the results of both queries to that array.


    Below is an example of that approach.

     

    1. I used a MembershipArray variable.

     

    2. The value of the ownedObjects request is used in an apply to each.

     

    3. Within the apply to each the results are append via the following json:

     

     

    {"id":"@{item()['id']}","displayName":"@{item()['displayName']}","role":"owner"}

     

     

     

    appendtoarray_loop.png

     

    4. For the memberOf results use the same variable and append to approach.

     

    appendtoarray_loop_members.png

     

    The end result should be one variable which contains all memberships for one specific user.

  • jimbobuk Profile Picture
    21 on at

    Hi and thanks for such a quick reply.

     

    The above is a great solution but doesnt get me to where I want to be with regards to membership.

     

    If you notice, some of the member roles have the same id as those in owner role.

    Ideally, I would like to keep all the owner role entries and emit/discard member roles where the id is the same

     

    Thanks again!

     

     

  • Expiscornovus Profile Picture
    33,844 Most Valuable Professional on at

    Hi @jimbobuk,

     

    In that case I would use two additional select actions to only retrieve the ids from both responses.

     

    You can use an intersection function to match the ids of those two arrays.

     

    Within the memberof Apply to each loop you can use a filter array to see if the id of the current item matches that intersection output.

     

    If it cannot find a match for the group id (by using a length equals 0 expression) it is only a member of the group and you can append it to the variable.

     

    Below is a quick screenshot of such a setup. Let me know if you need more details.

     

    intersection_match.png

  • jimbobuk Profile Picture
    21 on at

    Hi @Expiscornovus 

     

    I guess my code is incorrect. I am trying to follow your steps but the images are not too clear!
    Any chance you could send me a copy of the flow?

     

    Thank you!

  • Verified answer
    Expiscornovus Profile Picture
    33,844 Most Valuable Professional on at

    Hi @jimbobuk,

     

    Yes, no problem. Here is step-by-step walkthrough. Btw, the screenshots should be clickable (which should open a dialog with a clearer picture).

     

    1. Add a Initialize variable action

    a. Provide a name, OwnerandMemberArray

    b. Select Array Type

    c. In Value use []

     

    ownerandmemberarray.png

     

    2. Add a second Initialize variable action

    a. Provide a name, MembershipArray

    b. Select Array Type

    c. In Value use []

     

    membershiparray.png

    3. Add a Get User Profile (v2) action

    a. use the email of the user for which you want to lookup the memberships

     

    getuserprofile_example.png

     

    4. Add a Send an HTTP request (Office 365 Groups connector action)

    a. Rename action to Send an HTTP request - ownedObjects

    b. Use the following URI

    https://graph.microsoft.com/v1.0/users/@{outputs('Get_user_profile_(V2)')?['body/id']}/ownedObjects/?$select=id,displayName

     

    ownedobjectshttp.png

    5. Add a Select action

    a. Rename action to Select - ownedObjects

    b. Use the following expression in From

    body('Send_an_HTTP_request_-_ownedObjects')['value']

    c. Switch map to text mode and use the following expression

    item()['id']

     ownedobjectsselect.png

     

    6. Add an Apply to Each action

    a. Rename action to Apply to each - ownedObjects

    a. Use the following expression in the Select an output from previous steps field

    body('Send_an_HTTP_request_-_ownedObjects')['value']

     

    7. Add an append to Array variable action (within Apply to each - ownedObjects)

    a. Select the MembershipArray

    b. Use the following value

    {"id":"@{item()['id']}","displayName":"@{item()['displayName']}","role":"owner"}

    applytoeachownedobjects.png

     

    8. Add a Send an HTTP request (Office 365 Groups connector action)

    a. Rename action to Send an HTTP request - memberOf

    b. Use the following URI

    https://graph.microsoft.com/v1.0/users/@{outputs('Get_user_profile_(V2)')?['body/id']}/memberOf/?$select=id,displayName,role

     

    memberof.png

     

    9. Add a Select action

    a. Rename action to Select - memberOf

    b. Use the following expression in From

     

    body('Send_an_HTTP_request_-_memberOf')['value']

     

    c. Switch map to text mode and use the following expression

     

    item()['id']

     

     

    memberofselect.png

     

    10. Add a Set Variable action

    a. Select the OwnerandMemberArray

    b. Use the expression below for the Value field

    intersection(body('Select_-_ownedObjects'),body('Select_-_memberOf'))

     

    intersection_ownerandmemberarray.png

     

    11. Add an Apply to Each action

    a. Rename action to Apply to each - memberOf

    a. Use the following expression in the Select an output from previous steps field

     

    body('Send_an_HTTP_request_-_memberOf')['value']

     

    12. Add a Filter Array action (within Apply to each - memberOf)

    a. Use the OwnerandMemberArray variable in the From

    b. Click Edit in advanced mode and add the following expression

    @equals(item(), items('Apply_to_each_-_memberOf')['id'])

     

     

    13. Add a Condition action (within Apply to each - memberOf)

    a. Use the following check

    length(body('Filter_array'))

    is equal to 0

     

    14. Add a Append to array variable (within Apply to each - memberOf, in the If yes of the Condition)

    a. Rename action to Append to array variable - memberOf

    b. Select the MembershipArray

    c. Add the following to the Value field

    {"id":"@{item()['id']}","displayName":"@{item()['displayName']}","role":"member"}

     

    applytoeachmemberof.png

     

     

  • jimbobuk Profile Picture
    21 on at

    @Expiscornovus 

     

    Perfect! Thank you so much!

     

    Could I ask where you learnt Power Automate? Do you have any links etc as I would like to take some training!

     

    Thanks again

  • Expiscornovus Profile Picture
    33,844 Most Valuable Professional on at

    Hi @jimbobuk,

     

    Personally I just learned it from projects, reading the docs, following blogs, watching videos and helping out in these forums. 

     

    I would start with the Microsoft Self-pace learning modules:

    https://learn.microsoft.com/en-gb/training/browse/?products=power-automate&WT.mc_id=webupdates_GEP_PowerAutomate-web-wwl

     

    If that is not sufficient you can always have a look at third-party training companies.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 1,027

#2
Valantis Profile Picture

Valantis 809

#3
Haque Profile Picture

Haque 645

Last 30 days Overall leaderboard