We have a hosted discuss at http://discuss.codecademy.com. We have a few groups that we add users to based on their status on our site. A few weeks back we noticed users weren’t being added these additional groups.
So I tried using the api to add a test user to a group:
@client = DiscourseApi::Client.new(config['api_url'])
@client.api_key = config['api_key']
@client.api_username = config['api_username']
@client.user('kelvin14') # => {"id"=>7..... my user
@client.groups # {"id"=>51, "automatic"=>false, "name"=>"test_group", ... the group
@client.group_add(51, {usernames: ['kelvin14']})
Note the method is :get. Even though in discourse_api’s groups.rb the request is put("/admin/groups/#{group_id}/members.json", users) I see this happening with all requests are using get (deleting groups, etc)
Eventually I tried removing conn.use FaradayMiddleware::FollowRedirects, limit: 5 in client.rb which I see the requests actually using :put but status is 301 instead.
Is this an issue with the API you are using? As the Discourse Web App doesn’t submit a request to /admin/groups/51/members.json, instead it submits the request to /groups/51/members.json
Yes I noticed the same thing and took a look at the discourse repo, the /admin/groups are aliased to /groups
In routes.rb line 388
# aliases so old API code works
delete "admin/groups/:id/members" => "groups#remove_member", constraints: AdminConstraint.new
put "admin/groups/:id/members" => "groups#add_members", constraints: AdminConstraint.new
Unfortunately no further progress so far. I can’t find anything indicating an issue and I haven’t had time to try and create an app to add a user to a group.
Yes, the cause was our config still used http version of the url instead of the https version. Caused Faraday to only work on Get requests for put/delete/post will get redirected.