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
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.