# Groups metadata, how to use the code from the docs sample?

**URL:** https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677
**Category:** Documentation
**Tags:** server-framework
**Created:** [March 22, 2023, 10:52am UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677 "2023-03-22T10:52:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Andrey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/andrey/32/1495_2.png) [@Andrey](https://forum.heroiclabs.com/u/Andrey)
#### Post date: [March 22, 2023, 10:52am UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677/1 "2023-03-22T10:52:35Z")

</div>

There is a sample in the documentation [Heroic Labs Documentation | Groups](https://heroiclabs.com/docs/nakama/concepts/groups/#group-metadata:~:text=//%20Assuming%20a%20group%20metadata%20structure%20as%20follows)

```auto
// Assuming a group metadata structure as follows
type GroupMetadata struct {
	Roles map[string][]string `json:"roles"`
}

metadata := &GroupMetadata {
  Roles: map[string][]string{
    "000d8152-3258-457b-905b-05a9223c5c8c": { "bouncer" },
    "2c0c8e80-fcbc-4b61-901a-dace129f45f5": { "bouncer", "vip" },
  },
}

```

which shows that we can define a struct for a group metadata and then use it. But the sample doesn’t show how to write this struct to a group’s metadata. The problem is that the nk.GroupUpdate and nk.GroupCreate methods require map[string]interface{} parameter. So is the sample correct and if it is how can I write a custom struct to a group’s metadata?

---

<div class="post-metadata">

### Author: ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)
#### Post date: [March 22, 2023, 4:09pm UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677/2 "2023-03-22T16:09:38Z")

</div>

Hello @Andrey, the example is incorrect, it should be:

```go
metadata := map[string]any{
  "roles": map[string]any{
    "000d8152-3258-457b-905b-05a9223c5c8c": []string{"bouncer"},
    "2c0c8e80-fcbc-4b61-901a-dace129f45f5": []string{"bouncer", "vip"},
  },
}

```

@gabriel kindly update the sample in the docs please 🙏

---

<div class="post-metadata">

### Author: ![Andrey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/andrey/32/1495_2.png) [@Andrey](https://forum.heroiclabs.com/u/Andrey)
#### Post date: [March 22, 2023, 4:11pm UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677/3 "2023-03-22T16:11:15Z")

</div>

Hello @sesposito, thanks!

---

<div class="post-metadata">

### Author: ![Andrey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/andrey/32/1495_2.png) [@Andrey](https://forum.heroiclabs.com/u/Andrey)
#### Post date: [March 22, 2023, 4:14pm UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677/4 "2023-03-22T16:14:15Z")

</div>

It means that the code below (from the same sample) is incorrect too:

```auto
var metadata GroupMetadata
  if err := json.Unmarshal([]byte(groups[0].GetMetadata()), &metadata); err != nil {
    logger.Error("error deserializing metadata")
    return nil, runtime.NewError("error deserializing metadata", 13)
  }

```

---

<div class="post-metadata">

### Author: ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)
#### Post date: [March 22, 2023, 4:29pm UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677/5 "2023-03-22T16:29:57Z")

</div>

Thanks for pointing that out but I believe that the unmarshal code should work by just changing:

```auto
var metadata GroupMetadata

```

to

```auto
var metadata *GroupMetadata

```

or

```auto
metadata := &GroupMetadata{}

```

---

<div class="post-metadata">

### Author: ![Andrey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/andrey/32/1495_2.png) [@Andrey](https://forum.heroiclabs.com/u/Andrey)
#### Post date: [March 22, 2023, 4:32pm UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677/6 "2023-03-22T16:32:04Z")

</div>

Oh, yes, exactly, you are right 🙂

---

<div class="post-metadata">

### Author: ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)
#### Post date: [March 23, 2023, 11:23am UTC](https://forum.heroiclabs.com/t/groups-metadata-how-to-use-the-code-from-the-docs-sample/3677/7 "2023-03-23T11:23:21Z")

</div>

Hi @Andrey, a fix for this has just been made to our documentation. Thanks.
