I need to mass-create groups using the API

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.

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

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

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.

1 Like

@pfaffman Cool, Thanks, makes sense!

~B

1 Like

@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

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.

That’s how group names work.

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?

Sorry. I thought that I’d pointed you to Reverse engineer the Discourse API. 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.