如何通过 API 分配主题

Discourse Assign 暴露了以下 API 端点:

分配 (PUT /assign/assign.json)

必需参数:

  • target_id - 主题或帖子 ID
  • target_type - 必须是 "Topic""Post"

外加以下之一:

  • username - 要分配的用户名
  • group_name - 要分配的组名

可选参数:

  • note - 分配备注
  • status - 分配状态
  • should_notify - 发送通知 (默认值: true)

取消分配 (PUT /assign/unassign.json)

必需参数:

  • target_id - 主题或帖子 ID
  • target_type - 必须是 "Topic""Post"

示例 (curl)

# 将主题 123 分配给用户 "john"
curl -X PUT "https://your-discourse.com/assign/assign.json" \
  -H "Api-Key: YOUR_API_KEY" \
  -H "Api-Username: YOUR_USERNAME" \
  -H "Content-Type: application/json" \
  -d '{"target_id": 123, "target_type": "Topic", "username": "john"}'

# 分配给一个组而不是用户
curl -X PUT "https://your-discourse.com/assign/assign.json" \
  -H "Api-Key: YOUR_API_KEY" \
  -H "Api-Username: YOUR_USERNAME" \
  -H "Content-Type: application/json" \
  -d '{"target_id": 123, "target_type": "Topic", "group_name": "support-team"}'

备注

  • API 用户必须具有分配权限(位于允许分配的组中)
  • 您也可以使用 target_type: "Post" 和帖子 ID 来分配单个帖子

@opcourdis 上面的 Node.js 示例看起来是正确的!:+1:

2 个赞