Unable to create group owner with API


I need to migrate an old application to Discourse.
I’m using the APIs with CURL to create the users and groups.

I am using Discourse v3.1.0.beta5 +392

For users, I had no problem:
curl -X POST “site-discourse/users.json”
-H “Api-Key: api-key”
-H “Api-Username: api-username”
-F “name=name1”
-F “email=email1”
-F “password=password1”
-F “username=username1”
-F “active=true”
-F “approved=true”

For groups, I tried to create everything at once: the group, bio_raw, members and owners according to Discourse API Docs :
curl -X POST “site-discourse/admin/groups.json”
-H “Content-Type: application/json”
-H “Api-Key: api-key”
-H “Api-Username: api-username”
-d ‘{“name”:“groupe1”,“bio_raw”:“A propos du groupe1”,“usernames”:“username1”,“owner_usernames”: “owner_username1”}’

Group is created with name and bio_raw but no username1 and owner_username1

But I can create members in the following way:
curl -X PUT -d ‘{“usernames”: “username1,username2”}’
-H “Content-Type: application/json”
-H “Api-Key: api-key”
-H “Api-Username: api-username” site-discourse/admin/groups/$group_id/members.json

But I can’t create owner_usernames with API !

Thanks for your help

Franck Lucas

Hi FLucas and welcome to meta.discourse.org :blob_wave:

By reverse-engineering the API, I understood that the usernames must be separated with a comma without space. If you’re trying to add multiple users at once, it may be your issue.

I tested with the following payload:

    "group": {
        "name": "test",
        "bio_raw": "test",
        "full_name": "test",
        "usernames": "Canapin,adan",
        "owner_usernames": "cristopher_klocko,Canapin"

As a POST request to admin/groups.json, and it worked.


Thanks for your help,

Thanks to your example, I was able to create my group with all the data :

curl -X POST “https://site-discourse/admin/groups.json
-H “Content-Type: application/json”
-H “Api-Key: api-key”
-H “Api-Username: api-username”
-d ‘{
“group”: {
“name”: “name”,
“bio_raw”: “bio_raw”,
“full_name”: “full_name”,
“usernames”: “username1,unsaername2”,
“owner_usernames”: “owner_username1,owner_username2”

There was a structural problem in my API call !

Thank you for your quick response,

Frank Lucas


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.