How to identify "about" topics?


#1

I’m using the API to delete a category and all related topics. Here is what I do:

  • I get the category topic list
  • I iterate over category topics and delete them
  • I delete the empty category

The category “about” topic cannot be deleted. This is ok, because it is automatically removed when deleting the (almost) empty category. However, I would like to avoid trying to delete it when iterating over all topics (in order to avoid a server round-trip and an exception in my code). Is there a field I can check to see if a topic is an “about” topic?


(Felix Freiberger) #2

A good approximation should be requesting /t/<id>/1.json and checking for this property:

If missing, it’s probably the about post. (There might be other reasons for not being able to delete it.)

You might be better off running a Ruby script, which will be able to do something like this way more quickly. In the Rails console, this is how you get the id of the about topic for the staff category:

Category.find_by_slug("staff").topic_id

#3

Thanks a lot, @fefrei. Your advice about the Rails console incited me to look deeper into the category descriptor for a topic_id field. And I found… a topic_url field! Getting the topic_id is then just a matter of:

const topic_id = parseInt(topic_url.split('/').pop())

Thanks again!


(Felix Freiberger) #4

Good catch! I saw that, but didn’t notice it, because I had remembered that there was an id. :blush: