Discourse Add Group API

AI-generated summary

Discourse Add Group API Issue

dansingerman reported a mismatch between the Discourse API gem and the API’s expectations when creating a group. The gem posts a JSON packet with a root “group” key, but the controller method doesn’t expect it. zogstrip suggested fixing the issue by removing the root element from the packet posted by the gem. dansingerman created a PR to address the issue: https://github.com/discourse/discourse_api/pull/68.

I am using the discourse_api gem, and adding a group fails as follows:

client = DiscourseApi::Client.new
client.create_group(name: "some_group")
DiscourseApi::Error: {"errors"=>["Name must be at least 3 characters"]}

This is because of a mismatch between what the gem posts, and what the API expects.

The gem posts

{
    "group": {
        "name": "some_group",
        "visible": "true"
    }
}

But the controller method does not expect the root ‘group’ key:

 group = Group.new

 group.name = (params[:name] || '').strip

The discourse api documentation does not seem to mention groups: Discourse REST API Documentation

I am happy to fix this bug, but wanted to ask what we think the correct API design here is - should we fix it by removing the root element from the packet posted by the gem, or should the controller method be changed to deal with the root element?

2개의 좋아요

Yes, please :heart_eyes: .

I changed the API recently but didn’t update the gem :flushed:

2개의 좋아요

Here is the PR :smile:

https://github.com/discourse/discourse_api/pull/68

2개의 좋아요