Right now, in order to create a tag with the API, I create a temporary topic with the new tag, then delete the temporary topic. Is there a cleaner way?
I donât know, but a slightly less painful solution would be to create a post in the staff category (where Assets for site design is) and just add the new tags there.
The reason is that you want to create a bunch of tags so that users can use them in the future, but your community doesnât yet have posts with those tags?
Thanks @pfaffman.
You mean manually adding the new tag? Or is it possible to use the âUpdate a single topicâ API to add a tag to an existing topic? But in that case I would have to store the topic id, which is painfulâŠ
I guess this would be a legit use case. But mine is less legit: I use tags to store metadata (object ids from an external app).
Yeah, thatâs not a good idea, especially if each tag is only used once.
You should either have a separate database mapping the external IDs to Discourse topic IDs, or write a plugin and use topic custom fields (this is a problem since thereâs no existing mechanism to deliver these to the client, I think).
Another solution is to store the value in the post text.
Since there is a legit use case, I believe adding a ânew tagâ API in the future would be a plus.
I can feel the danger of using tags the way I do. But as I need to display, in Discourse, a list of the topics that relate to a specific external object, the âtags.showâ route seems the only wayâŠ
Well, what are the external objects? How many topics will one get? will a topic relate to multiple of these things?
You may be able to get away with using search.
The external objects are document subsections. One topic relates to one and only one subsection. A minimum guess is: 100 documents x 100 subsections per document = 10,000 subsections = 10,000 tags in a single Discourse instance. I know this is dangerous, but since Iâm in the prototype phase, tags are good enough for me.
Now I didnât think about the search page before⊠Iâve just done some tests, but sadly, the results are not formatted like a topic list (with the âRepliesâ, âViewsâ and âActivityâ columns). I guess a âtopics onlyâ checkbox that turns the result page into a standard Discourse topic list would be exactly what I need. 
Consider not pre-creating that many topics - thereâs often not much to discuss about the Bibliography. You can have a small service that takes a document & subsection ID and redirects you to either the existing topic or opens the composer pre-filled with the document link, subsection ID, etc.
title: Procedures for Smelling, section Keyboards
body: <https://link.to/document/1234#sec-26>
[write your text here]
lookup key: DISCUSS_1234_26
Then it polls /latest.json for new topics and checks them for the magic ID reference phrase I put in on the last line of the example.
Yes, I already have something like this. I donât create the subsection tags beforehand when a document is created. Iâve changed the âtag not foundâ page of a subsection so that it looks like an empty topic list with a âNew Topicâ button at the top. When user clicks the button, I create the tag on the fly using the API and open the composer pre-filled with the generated tag.
Yes there is: create a tag group populated with the tag you want to create (see the API here).
Il metodo sopra descritto per creare un tag tramite lâAPI (creando un gruppo di tag) presenta un inconveniente: funziona solo se sei un amministratore.
Ecco un altro modo per creare tag tramite lâAPI (ma sempre solo per gli amministratori): lâAPI non documentata /tags/upload.json, utilizzata dal menu Upload Tags. Utilizzala in questo modo:
const tags = ['tag1', 'tag2']
const file = new Blob([tags.join('\n')], { type: 'text/plain' })
const formData = new FormData()
formData.append('file', file)
$.ajax({
type: 'POST',
url: '/tags/upload.json',
data: formData,
contentType: false,
processData: false
})
Se prevedo di avere migliaia di tag, Ăš ancora una buona idea utilizzare questo workaround, creando un gruppo per ogni tag? I gruppi di tag sono flessibili quanto i tag?
Se lo sono, allora risolve il mio problema immediato. Altrimenti, cercherei di evitare la duplicazione (di tag + gruppo di tag per un singolo tag).
Mi dispiace, non lo so.
Ricordo che lâAPI permette, in una sola operazione, di creare piĂč tag allâinterno di un gruppo.
Grazie. SĂŹ, ci permette di creare piĂč tag nello stesso gruppo, ma solo durante la creazione. Possiamo aggiornarli, ma per farlo devo recuperare il gruppo, aggiungere i nuovi tag e poi inviarlo di nuovo. Non câĂš un endpoint specifico per lâaggiunta.
Per quanto riguarda la seconda idea che hai suggerito, quella con lâendpoint /tags/upload.json.
Ho trovato il pulsante di caricamento nellâinterfaccia. Ho creato un file CSV che funziona correttamente lĂŹ. Ma non riesco a farlo funzionare nĂ© in Postman nĂ© in Golang (se ti Ăš familiare, ho usato csv.NewWriter).
Hai qualche idea?
Scusa, non so come creare e pubblicare un blob con quelli.
Ho scoperto come farlo.
Se qualcuno ne ha bisogno, fatemi un fischio. Non lo pubblico qui perché Ú lungo e probabilmente irrilevante per il 99,99% della community.