[API] Cleaner way to create a tag?

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?

4 „Gefällt mir“

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.

5 „Gefällt mir“

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.

1 „Gefällt mir“

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. :slight_smile:

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.

4 „Gefällt mir“

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).

5 „Gefällt mir“

The above method to create a tag with the API (by creating a tag group) has one drawback: it works only if you’re an admin.

1 „Gefällt mir“

Und noch eine weitere Möglichkeit, Tags mit der API zu erstellen (aber immer noch nur für Administratoren): die undokumentierte API /tags/upload.json, die vom Menü „Tags hochladen

1 „Gefällt mir“

Wenn ich plane, Tausende von Tags zu verwenden, ist es dann immer noch eine gute Idee, diesen Workaround anzuwenden, also eine Gruppe für jedes Tag? Sind Tag-Gruppen so flexibel wie Tags?

Wenn ja, löst das mein unmittelbares Problem. Wenn nicht, würde ich versuchen, die Duplizierung (von Tag + Tag-Gruppe für nur ein Tag) zu vermeiden.

Entschuldigung, das weiß ich nicht.

Ich erinnere mich vage, dass die API es erlaubt, in einem Vorgang mehrere Tags in einer Gruppe zu erstellen.

Danke. Ja, damit können wir mehrere Tags in derselben Gruppe erstellen, aber nur beim Erstellen. Wir können aktualisieren, aber dafür muss ich die Gruppe abrufen, erweitern und dann zurücksenden. Es gibt keinen Endpunkt zum Erweitern.

Zu deiner zweiten Idee mit dem Endpunkt /tags/upload.json:

Ich habe die Schnittstelle für den Upload-Button gefunden. Ich habe eine CSV-Datei erstellt, die dort einwandfrei funktioniert. Aber ich bekomme es weder in Postman noch in Golang (falls du damit vertraut bist, habe ich csv.NewWriter verwendet) zum Laufen.

Hast du Ideen?

Entschuldigung, ich weiß nicht, wie man mit diesen Tools einen Blob erstellt und veröffentlicht.

Ich habe herausgefunden, wie es geht.

Wenn jemand es braucht, meldet euch bei mir. Ich poste es hier nicht, weil es lang ist und wahrscheinlich für 99,99 % der Community irrelevant ist.