Discourse-tagging plugin customization


(vikas kumar) #1

how we can create dynamically tags form our webapp using api or plugin.
so i can attach later to some topic.


(cpradio) #2

The easiest way that I can think of is using the Discourse API.

So you will need to either use an existing topic or create a new one, then using the API you submit a PUT request to that topic with the form data containing tags[] with the tags you want the topic to have.

If you use an existing topic, you will need to call the topic.json to get the current list of tags so you can append your new one to it.

Existing Topic:

  • Call the json for the existing topic, /t/testing-something-with-classes/76/1.json
  • Read the tags property
  • Append new tag to the existing tags
  • Send PUT to /t/testing-something-with-classes/76 with form data key of tags[] and the value containing the tags you are sending (each tag should be on its own – see screenshot below)

Note: Deleting all tags, you send a PUT command to the topic with a form data key of tags_empty_array and a value of true

Creating a Topic

  • Send POST command to /posts containing the raw, title, category, archetype (equal to regular), and tags[] (as noted above)

Note: You do not need to send tags_empty_array if you do not apply any tags to a new topic