C’è un modo per assegnare tramite API? Non lo vedo nella documentazione, ma mi piacerebbe essere sorpreso ![]()
Modifica: sembra che proverò a fare reverse engineering!
C’è un modo per assegnare tramite API? Non lo vedo nella documentazione, ma mi piacerebbe essere sorpreso ![]()
Modifica: sembra che proverò a fare reverse engineering!
Prima di tutto, il nostro obiettivo è avere un’API stabile, è uno sforzo pluriennale per raggiungerlo, ma è sicuramente un punto verso cui vogliamo arrivare.
Nel frattempo, un approccio ragionevole per il 2025 è fare affidamento sugli agenti AI per risolvere queste questioni:
Questo mostra come puoi fare affidamento sul nostro assistente GitHub per rispondere alla domanda!
Hai capito la cosa? Se sì, puoi condividere qui quello che hai imparato?
Ehi!
Non ancora! Questo progetto è stato posticipato per qualcosa di più urgente, ma ci tornerò la prossima settimana ![]()
@tobiaseigen questo funziona per me usando node js
var https = require(‘https’);
// Configurazione
var CONFIG = {
apiUrl: ‘YOURDISCOURSEDOMAIN’,
apiKey: ‘YOURAPIKEY’,
apiUsername: ‘YOURAPIUSER’,
assignToUsername: ‘USERNAMETOASSIGNTO’ // Nome utente a cui assegnare gli argomenti
};
// ID degli argomenti da assegnare
var topicIds = [634]; // cambia con l'ID dell'argomento
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('Stato:', res.statusCode);
console.log('Risposta grezza:', data);
try {
var response = JSON.parse(data);
if (res.statusCode === 200) {
console.log('Argomento ' + topicId + ' assegnato con successo');
} else {
console.log('Errore argomento ' + topicId + ':', response.errors || response.error_type || response);
}
} catch (e) {
console.log('Errore di analisi:', e.message);
}
if (callback) callback();
});
});
req.on(‘error’, function(e) {
console.error('Errore richiesta per argomento ’ + topicId + ‘:’, e);
if (callback) callback();
});
req.write(postData);
req.end();
}
// Esegui in sequenza
var index = 0;
function next() {
if (index < topicIds.length) {
assignTopic(topicIds[index], function() {
index++;
setTimeout(next, 500);
});
}
}
console.log('Assegnazione argomenti:', topicIds.join(‘, ‘));
console.log('Assegna a:', CONFIG.assignToUsername);
console.log(’’);
next();
I Discourse Assign espone i seguenti endpoint API:
/assign/assign.json)Parametri obbligatori:
target_id - L’ID dell’argomento o del posttarget_type - O \"Topic\" o \"Post\"Più uno dei seguenti:
username - Nome utente a cui assegnaregroup_name - Nome del gruppo a cui assegnareParametri opzionali:
note - Nota di assegnazionestatus - Stato di assegnazioneshould_notify - Invia notifiche (default: true)/assign/unassign.json)Parametri obbligatori:
target_id - L’ID dell’argomento o del posttarget_type - O \"Topic\" o \"Post\"# Assegna l'argomento 123 all'utente "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"}'
# Assegna a un gruppo invece
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"}'
Note
target_type: "Post" con l’ID del post@opcourdis l’esempio Node.js sopra sembra corretto! ![]()
Grazie per aver condiviso, è bello vedere che possiamo includere tutti quei parametri