Adding group members vs adding owners: data format is different

When using the API to add members and owners to a group, it looks like the required data format is different. This may be intentional but I’d like to know why (it’s breaking pydiscourse, the best library I can find for interacting with the Discourse API in Python).

Adding a member to a group:

curl -X PUT "https://{mydomain}/admin/groups/{group_id}/members.json" \ 
    -d 'usernames={my-username}' \
    -H "Api-Key: {my-api-key}" \
    -H "Api-Username: {my-api-username}"

Adding an owner to a group:

curl -X PUT "https://{mydomain}/admin/groups/{group_id}/owners.json" \ 
    -d 'group[usernames]={my-username}' \
    -H "Api-Key: {my-api-key}" \
    -H "Api-Username: {my-api-username}"

I’m curious why the key for the username param in the owners endpoint needs to be written as group[usernames] instead of just usernames?

The only reason I can give as to why is that they are actually using two different controllers.

The add members endpoint is mapped to the groups controller:

PUT /admin/groups/:id/members(.:format) groups#add_members 

And the add owners endpoint is mapped to the admin groups controller.

PUT /admin/groups/:id/owners(.:format) admin/groups#add_owners

It’s unlikely we will update this endpoint because lots of integrations already use this endpoint as is. You best bet is to open up an issue in the pydiscourse repo. You could also monkey patch a fix for add_group_owner in your python app until it gets resolved inside of pydiscourse.

1 Like