Hinzufügen von Gruppenmitgliedern vs. Hinzufügen von Besitzern: Datenformat ist unterschiedlich

Wenn Sie die API verwenden, um Mitglieder und Besitzer zu einer Gruppe hinzuzufügen, scheint das erforderliche Datenformat unterschiedlich zu sein. Das mag beabsichtigt sein, aber ich würde gerne wissen, warum (es bricht pydiscourse, die beste Bibliothek, die ich für die Interaktion mit der Discourse-API in Python finden kann).

Ein Mitglied zu einer Gruppe hinzufügen:

curl -X PUT "https://{mydomain}/admin/groups/{group_id}/members.json" \
    -d 'usernames={my-username}' \
    -H "Api-Key: {my-api-key}" \
    -H "Api-Username: {my-api-username}"

Einen Besitzer zu einer Gruppe hinzufügen:

curl -X PUT "https://{mydomain}/admin/groups/{group_id}/owners.json" \
    -d 'group[usernames]={my-username}' \
    -H "Api-Key: {my-api-key}" \
    -H "Api-Username: {my-api-username}"

Mich wundert, warum der Schlüssel für den Parameter „usernames" im Endpunkt für Besitzer als group[usernames] geschrieben werden muss und nicht einfach als usernames.

The only reason I can give as to why is that they are actually using two different controllers.

The add members endpoint is mapped to the groups controller:

PUT /admin/groups/:id/members(.:format) groups#add_members 

And the add owners endpoint is mapped to the admin groups controller.

PUT /admin/groups/:id/owners(.:format) admin/groups#add_owners

It’s unlikely we will update this endpoint because lots of integrations already use this endpoint as is. You best bet is to open up an issue in the pydiscourse repo. You could also monkey patch a fix for add_group_owner in your python app until it gets resolved inside of pydiscourse.

1 „Gefällt mir“