How do I assign a topic via the API

The Discourse Assign exposes these API endpoints:

Assign (PUT /assign/assign.json)

Required parameters:

  • target_id - The topic or post ID
  • target_type - Either "Topic" or "Post"

Plus one of:

  • username - Username to assign to
  • group_name - Group name to assign to

Optional parameters:

  • note - Assignment note
  • status - Assignment status
  • should_notify - Send notifications (default: true)

Unassign (PUT /assign/unassign.json)

Required parameters:

  • target_id - The topic or post ID
  • target_type - Either "Topic" or "Post"

Examples (curl)

# Assign topic 123 to user "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"}'

# Assign to a group instead
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"}'

Notes

  • The API user must have assign permissions (be in an assign-allowed group)
  • You can also assign individual posts using target_type: “Post” with the post ID

@opcourdis the Node.js example above looks correct! :+1:

2 Likes