Can't delete the default topic of a category

Hello I am trying to use the API endpoint to delete topics.

I can delete “normal” topics but I ran into the problem that the default topic can not be deleted. The one called “About the ________ category”

{{baseUrl}}/t/{{id}}.json

Here are my questions:

  • How can I delete this topic using the API?
  • How can I identify that topic using the API so that it is skipped.

Example

    url = base_url + "/c/" + slug + "/22.json"
    response = requests.request("GET", url, headers=headers, data=payload)

    for topic in response.json()["topic_list"]["topics"]:
        # Deletes each topic

        url =  base_url + "/t/topic_id.json".replace("topic_id", str(topic["id"])  )
        response = requests.request("DELETE", url, headers=headers, data=payload)

you can set the category description topics to “unlisted”. i do that to all of mine. i suspect you can identify the unlisted topics via the api?

3 Likes

Can you share why you want to remove these topics? Those are special topics that can’t and aren’t meant to be deleted.

If your goal is to delete all the topics and then delete the category, you can delete the category without deleting the About topic.

When people want to get rid of the About topics somehow, unlisting them as @Lilly suggest is the way to go.

I think these posts don’t have any unique attributes. They are identified as being special topics from the category table, via the topic_id column.

You can get them with the /c/{id}/show.json endpoint: https://docs.discourse.org/#tag/Categories/operation/getCategory.
Look for the topic_url key.

For example:

https://meta.discourse.org/c/7/show.json

"topic_url": "/t/about-the-dev-category/1026"

A bit more technical info if that interest you.

The deletion protection :shield: is here: https://github.com/discourse/discourse/blob/7ecaf6295daf8759aa98d00e7035c4dc0f853303/lib/guardian/topic_guardian.rb#L165

And the method used is defined here: https://github.com/discourse/discourse/blob/7ecaf6295daf8759aa98d00e7035c4dc0f853303/app/models/topic.rb#L1852

2 Likes