尝试通过 API (PUT groups/{id}.json) 更新群组监视列表时出错

优先级/严重性:

中到高

平台:

Python 脚本以及 cURL 命令行

Discourse 服务器版本:

3.6.0.beta3-latest (6adb4f8e84)

描述:

当尝试更新现有组的 watching_category_ids 时,我的 Python 脚本(使用简单的 “requests.put”)报告以下错误:

_doPut> 请求出错: 422 Unprocessable Entity {'user_count': 2, 'errors': ['您提供的请求参数无效: update_existing_users']}

即使我的 JSON 数据中没有名为 update_existing_users 的参数。

使用 cURL 进行检查:

curl -k -L -X PUT -H 'api-key:xyz’ \
   -H 'api-username:system'  \
   -H 'Accept:application/json;charset=utf-8'  \
   -H 'Content-Type:application/json'   \
   --data '{"group":{"name":"eb-chair-exo","watching_category_ids":[336,337]}}' \
   https://cms-phys-talk.web.cern.ch/groups/46.json

我得到了相同的错误:

{“user_count”:2,“errors”:[“您提供的请求参数无效: update_existing_users”]}%

可重现步骤:

curl -k -L -X PUT -H 'api-key:xyz’ \
   -H 'api-username:system'  \
   -H 'Accept:application/json;charset=utf-8'  \
   -H 'Content-Type:application/json'   \
   --data '{"group":{"name":"eb-chair-exo","watching_category_ids":[336,337]}}' \
   https://cms-phys-talk.web.cern.ch/groups/46.json

编辑:已添加 Discourse 服务器版本

是的,那个端点有点奇怪。我们想提醒工作人员可能受影响的用户数量,并让他们选择是追溯性地应用更改还是不应用。

这就是您在服务器响应中看到“{ 'user_count': 2, ... }”的原因。

我已经澄清了错误消息,使其更有意义,并改进了前端代码以更好地处理此“用例”,同时添加了规范。

1 个赞

您好,感谢您的快速响应!:slight_smile:

不幸的是,我仍然感到困惑:我需要为给定组设置 watching_category_ids 的值,即使错误消息现在已更改,它仍然是 422 错误。那么,我如何使用 rest-API 通过脚本使用新的 watching_category_ids 列表来更新该组呢?

我已经尝试在 PUT 调用的 json 数据中添加 "update_existing_users”=True,但收到的错误与报告的一样。:frowning:

再次感谢,

致敬,Andreas

期望字符串 “true”——小写。

非常感谢,@zogstrip!现在可以用了!:smiley:

(仅供参考,"update_existing_users"=True 必须在发送到 JSON 中的 “group” 项之外/与之平行(此处以 Python 语法显示,因此 True 会被翻译成字符串 "true"):

            jsonData={
                "group": {
                    "name": f"{groupName}",
                    "watching_category_ids": newWatchList,
                },
                "update_existing_users": True,
            },

此主题在 20 小时后自动关闭。不再允许新的回复。