looking at discourse/discourse source code search discourse assign plugin and figure out the exact endpoints and payloads I should use to assign and unassign a topic, document with a curl example and example reply
looking at discourse/discourse source code search discourse assign plugin and figure out the exact endpoints and payloads I should use to assign and unassign a topic, document with a curl example and example reply
Let me start by searching for assign-related files in the repository.
I’ll help you find the exact endpoints and payloads for the Discourse assign plugin. Let me search for the relevant files in the discourse/discourse repository.
Searched for 'assign, plugin' in discourse/discourse/main
Searched for 'assign plugin controller' in discourse/discourse
Now let me get the actual assign controller file to see the exact endpoints:
Retrieved content of plugins/discourse-assign/app/controllers/discourse_assign/assign_controller.rb, plugins/discourse-assign/config/routes.rb from discourse/discourse@main
Perfect! I found the assign plugin controller. Now let me examine the specific code to document the endpoints and payloads. Let me also check for more information about the parameters that can be used.
Searched for 'Assigner.new assign' in discourse/discourse
Perfect! Now I have enough information to document the assign and unassign endpoints. Let me create comprehensive documentation with curl examples.
Based on the source code, here are the exact endpoints and payloads for assigning and unassigning topics in Discourse:
All assign endpoints are mounted at /assign
PUT /assign/assign.json
target_id (integer) - The ID of the topictarget_type (string) - The type of target (e.g., “Topic”)username (string) - Username to assign to, ORgroup_name (string) - Group name to assign tonote (string) - A note about the assignmentstatus (string) - Assignment status (requires enable_assign_status setting enabled)should_notify (boolean) - Whether to send notification (default: true)Requires API key or session authentication with assign permissions.
curl -X PUT "https://your-discourse.com/assign/assign.json" \
-H "Content-Type: application/json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME" \
-d '{
"target_id": 123,
"target_type": "Topic",
"username": "john_doe",
"note": "Please review this topic",
"status": "In Progress",
"should_notify": true
}'
curl -X PUT "https://your-discourse.com/assign/assign.json" \
-H "Content-Type: application/json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME" \
-d '{
"target_id": 123,
"target_type": "Topic",
"group_name": "moderators",
"note": "Team review needed",
"should_notify": true
}'
{
"success": "OK"
}
400 Bad Request - Various assignment failures:
{
"error": "john_doe is already assigned to this topic"
}
403 Forbidden - User doesn’t have permission:
{
"error": "You are not permitted to view the requested resource."
}
404 Not Found - Topic or user not found:
{
"error": "The requested URL or resource could not be found."
}
Possible Error Messages:
"already_assigned" - User already assigned to this topic"forbidden_assign_to" - User cannot assign to target user"forbidden_assignee_not_pm_participant" - Assignee not a PM participant"forbidden_assignee_cant_see_topic" - Assignee cannot see the topic"group_already_assigned" - Group already assigned"too_many_assigns_for_topic" - Topic has reached assignment limit"too_many_assigns" - User has reached max assigned topicsPUT /assign/unassign.json
target_id (integer) - The ID of the topictarget_type (string) - The type of target (e.g., “Topic”)Requires API key or session authentication with assign permissions.
curl -X PUT "https://your-discourse.com/assign/unassign.json" \
-H "Content-Type: application/json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME" \
-d '{
"target_id": 123,
"target_type": "Topic"
}'
{
"success": "OK"
}
403 Forbidden - User doesn’t have permission
404 Not Found - Topic not found or invalid target type
GET /assign/suggestions.json
curl -X GET "https://your-discourse.com/assign/suggestions.json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME"
{
"assign_allowed_on_groups": ["staff", "moderators"],
"assign_allowed_for_groups": ["trust_level_4"],
"suggestions": [
{
"id": 1,
"username": "john_doe",
"name": "John Doe",
"avatar_template": "/user_avatar/discourse.example.com/john_doe/{size}/123_2.png"
}
]
}
Target Types: The code validates target_type must be a valid assignment type (typically “Topic” or “Post”)
Permissions: Users must have the can_assign? permission, which is controlled by the assign_allowed_on_groups site setting
Assignment Limits:
max_assigned_topics site settingASSIGNMENTS_PER_TOPIC_LIMIT (defined in Assigner class)Status Feature: Assignment statuses require the enable_assign_status site setting to be enabled
Notifications: By default, assigned users receive notifications unless should_notify is explicitly set to false
Group Assignments: When assigning to a group, all members with appropriate permissions can see and act on the assignment
You can also send parameters as form data instead of JSON:
# Assign
curl -X PUT "https://your-discourse.com/assign/assign.json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME" \
-d "target_id=123" \
-d "target_type=Topic" \
-d "username=john_doe" \
-d "note=Review needed"
# Unassign
curl -X PUT "https://your-discourse.com/assign/unassign.json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME" \
-d "target_id=123" \
-d "target_type=Topic"
This documentation is based on the actual controller code from plugins/discourse-assign/app/controllers/discourse_assign/assign_controller.rb in the discourse/discourse repository.