I’m trying to use the Discourse API to update a group with a particular user. In the docs that I have found, there wasn’t any information on this, only the ability to create a group.
I also tried to watch the XHR request when I’m actually updating a group on discourse with another user. The API seems to be calling this URL: groups/[group_name]/members.json, which I can call with a GET and get back the group info, but I get an error when I tried to PUT with the usernames parameter.
{
"errors": [
"You are not permitted to view the requested resource."
],
"error_type": "invalid_access"
}
Any advice on how I can get around this? I have put my API key and username as a query as per the API documentation instructions.
That’s the right approach. Discourse is very happy to reply with a 403 if anything isn’t as expected. I’ve been struggling with this too…
I recommend using a Proxy (if you’re using Windows, look at Fiddler) to carefully compare your request with a correct one from the web interface. Things to look at:
Are you really using PUT?
Do all parameters match 100%?
Do any relevant headers differ?
Also triple-check that you are really giving a correct API key and a valid username.
Is the groupID supposed to be a number or the name of the group? From the API call I saw it was an ID. I actually get a 200 success when I use the ID, but the groups don’t seem to be updating for that user
Yes @jefflau you are correct it is a numeric group ID that is required.
I’ve updated the post above to reflect one method of implementing adding by name…
… specifically looks up the group ID by name, if not found create a group with that name…
Uses post and uses a different url related to the user. Is there a difference to doing it one way or the other? I just couldn’t figure out what I was doing wrong with the other way.
Feel like someone should be keeping the API docs up to date. Shouldn’t have to go around fishing for what API calls work and what not!
I’m getting 404 on PUT /admin/groups/{group_id}/owners.json on discourse 3.1.0.beta2 (f8863b0f98); is this topic up to date?
EDIT: it seems that one should use PUT /groups/{group_id}/owners.json instead. Additionally the input data is now {"members": "username1,username2,..."}.