# Listing groups of a user

**URL:** <https://forum.heroiclabs.com/t/listing-groups-of-a-user/1369>\
**Category:** Game Design\
**Tags:** sdk-unity\
**Created:** [February 12, 2021, 3:02pm UTC](https://forum.heroiclabs.com/t/listing-groups-of-a-user/1369 "2021-02-12T15:02:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hasosyn](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hasosyn](https://forum.heroiclabs.com/u/hasosyn)\
**Post date:** [February 12, 2021, 3:02pm UTC](https://forum.heroiclabs.com/t/listing-groups-of-a-user/1369/1 "2021-02-12T15:02:32Z")

</div>

Hello,

I was trying to get the user groups. Even though user joined 2 different groups the code in the documentation i put below returns only one of them.

Can anyone tell me what the problem might be ?

Thanks…

The code:

string userId =session.UserId;

```
    var result = await client.ListUserGroupsAsync(session, userId);

    foreach (var ug in result.UserGroups)

    {

        var g = ug.Group;

        Debug.LogFormat("Group '{0}' role '{1}'", g.Id, ug.State);

    }
```

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [February 12, 2021, 8:23pm UTC](https://forum.heroiclabs.com/t/listing-groups-of-a-user/1369/2 "2021-02-12T20:23:30Z")

</div>

@hasosyn could you share the code where you add the user to the groups?

Could you also confirm via the Nakama Console that the user is actually in both groups?

Also, welcome to Nakama!

---

<div class="post-metadata">

**Author:** ![hasosyn](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hasosyn](https://forum.heroiclabs.com/u/hasosyn)\
**Post date:** [February 15, 2021, 7:12am UTC](https://forum.heroiclabs.com/t/listing-groups-of-a-user/1369/3 "2021-02-15T07:12:36Z")

</div>

Hello again @lugehorsam,  
// group already open so user should have been in the group  
const string groupId = “67616c96-9ee0-45b9-9fae-348dc974e133”;// example  
await client.JoinGroupAsync(session, groupId);

// this is how i am trying to get the data(it returns only one group which user is superadmin)  
string userId =session.UserId;  
var result = await client.ListUserGroupsAsync(session, userId);  
foreach (var ug in result.UserGroups)  
{  
var g = ug.Group;  
Debug.LogFormat(“Group ‘{0}’ role ‘{1}’”, g.Id, ug.State);  
}

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [February 15, 2021, 2:49pm UTC](https://forum.heroiclabs.com/t/listing-groups-of-a-user/1369/4 "2021-02-15T14:49:53Z")

</div>

@hasosyn You’re only making one join group call.

---

<div class="post-metadata">

**Author:** ![hasosyn](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hasosyn](https://forum.heroiclabs.com/u/hasosyn)\
**Post date:** [February 16, 2021, 6:44am UTC](https://forum.heroiclabs.com/t/listing-groups-of-a-user/1369/5 "2021-02-16T06:44:44Z")

</div>

Hi again, @lugehorsam  
I see what you mean  
thank you for your help 🙂
