# I need to mass-create groups using the API

**URL:** https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055
**Category:** Development
**Tags:** rest-api
**Created:** [October 5, 2022, 6:56pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055 "2022-10-05T18:56:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![boyan.biandov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/boyan.biandov/32/276124_2.png) [@boyan.biandov](https://meta.discourse.org/u/boyan.biandov)
#### Post date: [October 5, 2022, 6:56pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055/1 "2022-10-05T18:56:58Z")

</div>

Hi everyone,

I need to mass-create groups using the API but the JSON does NOT accept an array of multiple values, it only works if I create one group per API call.

> **[Discourse API Docs](https://docs.discourse.org/#tag/Groups/operation/createGroup)**

Ideally I want to fire one create call and have the names as JSON array but that triggers Status:  
500 (Internal Server Error)

I expected that the below would work but it doesn’t - help! We’re talking 200+ groups, I am using POST for https://{defaultHost}/admin/groups.json just as the documentation calls for

```plaintext
{
  "group": [
    {
      "name": "X"
    },
    {
      "name": "Y"
    },
    {
      "name": "Z"
    }
]
}

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 5, 2022, 7:13pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055/2 "2022-10-05T19:13:31Z")

</div>

It looks to me like it’s called `createGroup` not `createGroups`. It says that it “Creates a group” not “Creates as many groups as you want.”

You’ll need to loop through the values yourself and call it for each group you want to add. You probably want to either insert some delay or build in code that will re-try when you hit rate limits.

---

<div class="post-metadata">

### Author: ![boyan.biandov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/boyan.biandov/32/276124_2.png) [@boyan.biandov](https://meta.discourse.org/u/boyan.biandov)
#### Post date: [October 5, 2022, 10:09pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055/3 "2022-10-05T22:09:38Z")

</div>

@pfaffman Cool, Thanks, makes sense!

~B

---

<div class="post-metadata">

### Author: ![boyan.biandov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/boyan.biandov/32/276124_2.png) [@boyan.biandov](https://meta.discourse.org/u/boyan.biandov)
#### Post date: [October 13, 2022, 3:25pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055/4 "2022-10-13T15:25:16Z")

</div>

@pfaffman It worked just as expected writing a little script but now I’m facing another issue. The API only permits “name” and not “full name” so I have no means to populate full name using the create method. The only permissible field “name” also does not allow spaces so I end up with ton of groups with blank full name and “name” having to use “\_”

Ideally I would like to be able to provide full name in addition to name when creating groups using the API?

Thanks  
Boyan

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 13, 2022, 3:28pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055/5 "2022-10-13T15:28:25Z")

</div>

> [@boyan.biandov](#):
>
> The API only permits “name” and not “full name

That doesn’t make sense, as the API is what the front end uses to create groups. Since it’s possible to create full names on the ux, you can create them in the API.

> [@boyan.biandov](#):
>
> The only permissible field “name” also does not allow space

That’s how group names work.

---

<div class="post-metadata">

### Author: ![boyan.biandov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/boyan.biandov/32/276124_2.png) [@boyan.biandov](https://meta.discourse.org/u/boyan.biandov)
#### Post date: [October 13, 2022, 3:39pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055/6 "2022-10-13T15:39:42Z")

</div>

Kindly point me to where do I specify full name? I respectfully disagree that the API is used by the front end since clearly I get to edit full name using the front end but here I do not see full name?

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/5/d/a5dbc07f17e6d2b9124641b8d278c001acc5238d.png)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 13, 2022, 5:58pm UTC](https://meta.discourse.org/t/i-need-to-mass-create-groups-using-the-api/241055/7 "2022-10-13T17:58:36Z")

</div>

Sorry. I thought that I’d pointed you to [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576). I recommend either using the reverse engineering method or look directly at the source. I don’t think that anyone who’s actively developing Discourse actually uses those docs, so I don’t trust them to be complete or up to date.
