Is there a way to assign via API? I don’t see it in the docs, but I would love to be surprised ![]()
Edit: looks like I’ll be trying to reverse engineer it!
In a Support discussion titled How do I assign a topic via the API, users explore whether Discourse’s API supports topic assignment. putty initially asks if it’s possible and considers reverse-engineering it, while sam acknowledges the API is still evolving but suggests using AI tools like the GitHub helper bot for interim solutions. tobiaseigen follows up for updates, and putty replies that progress is paused but will resume soon. Later, opcourdis shares a working Node.js script using PUT /assign/assign.json, which accepts parameters like target_id, target_type, and username. zogstrip confirms this endpoint’s documentation, detailing required and optional fields (including group_name, note, status, should_notify), and provides curl examples for assigning topics or posts to users or groups. They also note the API user must have assign permissions. opcourdis thanks them for clarifying the full parameter support. The consensus is that while not officially documented yet, the assignment API is functional and usable with proper permissions.
Is there a way to assign via API? I don’t see it in the docs, but I would love to be surprised ![]()
Edit: looks like I’ll be trying to reverse engineer it!
First of all, our goal is to have a stable API, it is a multi year effort to get there, but it is certainly a place we want to get.
In the meant time a reasonable 2025 trick you can use is lean on AI agents to figure this stuff out:
This shows how you can lean on our GitHub helper to answer the question!
Did you figure this out? If so, can you share your learning here?
Hey!
Not yet! This project got bumped back for something more pressing, but I’ll be back on it next week ![]()
@tobiaseigen this works for me using node js
var https = require(‘https’);
// Configuration
var CONFIG = {
apiUrl: ‘YOURDISCOURSEDOMAIN’,
apiKey: ‘YOURAPIKEY’,
apiUsername: ‘YOURAPIUSER’,
assignToUsername: ‘USERNAMETOASSIGNTO’ // Username to assign topics to
};
// Topic IDs to assign
var topicIds = [634]; //change with the topic id
function assignTopic(topicId, callback) {
var postData = JSON.stringify({
target_id: topicId,
target_type: ‘Topic’,
username: CONFIG.assignToUsername
});
var options = {
hostname: CONFIG.apiUrl,
port: 443,
path: ‘/assign/assign.json’,
method: ‘PUT’,
rejectUnauthorized: false,
headers: {
‘Api-Key’: CONFIG.apiKey,
‘Api-Username’: CONFIG.apiUsername,
‘Content-Type’: ‘application/json’,
‘Content-Length’: postData.length
}
};
var req = https.request(options, function(res) {
var data = ‘’;
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
console.log('Status:', res.statusCode);
console.log('Raw response:', data);
try {
var response = JSON.parse(data);
if (res.statusCode === 200) {
console.log('Topic ' + topicId + ' successfully assigned');
} else {
console.log('Topic ' + topicId + ' error:', response.errors || response.error_type || response);
}
} catch (e) {
console.log('Parse error:', e.message);
}
if (callback) callback();
});
});
req.on(‘error’, function(e) {
console.error('Request error for topic ’ + topicId + ‘:’, e);
if (callback) callback();
});
req.write(postData);
req.end();
}
// Run sequentially
var index = 0;
function next() {
if (index < topicIds.length) {
assignTopic(topicIds[index], function() {
index++;
setTimeout(next, 500);
});
}
}
console.log(‘Assigning topics:’, topicIds.join(‘, ‘));
console.log(‘Assign to:’, CONFIG.assignToUsername);
console.log(’’);
next();
The Discourse Assign exposes these API endpoints:
/assign/assign.json)Required parameters:
target_id - The topic or post IDtarget_type - Either "Topic" or "Post"Plus one of:
username - Username to assign togroup_name - Group name to assign toOptional parameters:
note - Assignment notestatus - Assignment statusshould_notify - Send notifications (default: true)/assign/unassign.json)Required parameters:
target_id - The topic or post IDtarget_type - Either "Topic" or "Post"# 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
@opcourdis the Node.js example above looks correct! ![]()
Thanks for sharing nice to so see we can include all those parameters