是否可以在一次 API POST 调用中创建新类别并设置权限?
或者是否需要后续的 PUT 调用来设置权限?
我查看了 API 逆向工程主题,并尝试设置一个调用来遵循手动创建类别时发出的 POST 调用(浏览器负载:payload = {“name”:“workspaces1”,“color”:“0088CC”,“text_color”:“FFFFFF”,“permissions”:{“everyone”:1},“allow_badges”:true,“category_setting_attributes”:{},“custom_fields”:{},“form_template_ids”:,“required_tag_groups”:,“topic_featured_link_allowed”:true,“search_priority”:0})以及这个 discourse_api/lib/discourse_api/api/categories.rb at d5ea30ba4abe6dcd90fb5a9f432c548dea9eaa0c · discourse/discourse_api · GitHub
带有以下内容的 POST 调用
CATEGORY_CREATION_ENDPOINT = f"{DISCOURSE_API_URL}/categories.json"
data = {
"name": "workspace5",
"color": "0088CC",
"text_color": "FFFFFF"
}
response = requests.post(CATEGORY_CREATION_ENDPOINT, headers=headers, data=data)
成功了,
而带有权限的 POST 调用返回 500 错误
CATEGORY_CREATION_ENDPOINT = f"{DISCOURSE_API_URL}/categories.json"
data = {
"name": "workspace5",
"color": "0088CC",
"text_color": "FFFFFF",
"permissions": {"admins": "1"}
}
response = requests.post(CATEGORY_CREATION_ENDPOINT, headers=headers, data=data)
这会产生 500 错误