Cannot fathom the API for adding and removing group owners

I wish to add and remove group owners using the API. This is not documented in the api docs.

Tracing the calls while logged in as admin, make user owner is

PUT groups/<gid>/owners with a payload of usernames=nikkilocke(note no admin!)

Remove user from owners is

DELETE admin/groups/<gid>/owners with a payload of user_id=<uid>

Studying the source code shows:


      def group_add_owners(group_id, args)
        args = API.params(args).required(:usernames).to_h
        put("/admin/groups/#{group_id}/owners.json", group: args)
      end

      def group_remove_owners(group_id, args)
        args = API.params(args).required(:usernames).to_h
        delete("/admin/groups/#{group_id}/owners.json", group: args)
      end

and this code doesn’t seem to have changed since 2023.

I am running Discourse 3.4.7, and the add owners entry point in the source code gives a 404 error.

Urls I have tried:

PUT /groups/384/owners usernames=nikkilocke OK

PUT /admin/groups/384/owners group[usernames]=nikkilocke 404 error

DEL /admin/groups/384/owners group[usernames]=nikkilocke OK

DEL /admin/groups/384/owners user_id = 12 OK

Can anyone advise me what’s going on, and which urls to use for this, please?

I assume that that’s a typo and not the cause of your error?

2 Likes

The best and surest documentation for the API is Reverse engineer the Discourse API

Are you sure that you have a valid API key and that you are passing it correctly? A 404 error is expected if you are not properly authenticated.

Are you able to do any requests that require authorization?

As I said in the original post, 3 out of the 4 possibilities work fine (with the same API key).

1 Like

Ah. Sorry. The “OK” at the end of the line was somehow too subtle for me to follow.

When I add an owner, I see this PUT request https://example.com/groups/75/owners.json with usernames= pfaffman123 in the form data.

Did you follow the reverse engineering steps I linked to?