Can't delete the default topic of a category

AI-generated summary

The discussion revolves around deleting the default topic of a category using the Discourse API. jucajuca is trying to delete these topics, but they cannot be deleted normally. Lilly suggests setting the category description topics to “unlisted” as a solution. Canapin explains that these topics are special and cannot be deleted; instead, they can be unlisted.

To identify these special topics, Canapin suggests using the /c/{id}/show.json endpoint to look for the topic_url key. Alternatively, the category can be deleted without deleting the About topic. The technical reason behind the deletion protection of these topics is linked to the Discourse GitHub repository.

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?

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: discourse/lib/guardian/topic_guardian.rb at 7ecaf6295daf8759aa98d00e7035c4dc0f853303 · discourse/discourse · GitHub

And the method used is defined here: discourse/app/models/topic.rb at 7ecaf6295daf8759aa98d00e7035c4dc0f853303 · discourse/discourse · GitHub