API - Add User to moderator group

I’m looking to add moderator group to a user using API.

here is the call I used
https://discourse.example.com/groups/{group_id}/members.json

Even though I get an error

“errors”: [

    "You are not permitted to view the requested resource."

],

"error_type": "invalid_access"

It’s most likely that you’re not passing the API key properly.

Thanks for your reply.

I thought of the same at one point but I have admin api key and its still the same error

Additionally, instead of moderator if I try to add the user to any other custom group it gets added successfully.

Wait. You just want to make a user a moderator? You just need to update the moderator field in the user record. It’s not really a group. That’s the problem.

You’d do this with the user API not the group API.

1 Like

I’m not certain is this is method if you are referring to.
However, I tried assigning moderator using this method.

https://discourse.example.com/admin/users/{id}/groups

{
“group_id”: 2 //moderator
}

and I got the following error.

“You cannot modify an automatic group”

Group editing is not how you make someone a moderator. Look at the admin page for that user, press the Grant Moderation button, and watch the f12 console to see what requests were sent.

2 Likes

Vow this is really cool… Awesome Thank you Jeff!

1 Like