Subcategory Name

When I send GET request to categories.json, I get subcategoryIds of Ids for any category but how do I get the corresponding names of subcategories using the API.

Basically I want the name and id of all the categories/subcategories.

You may find this post useful How to reverse engineer the Discourse API

1 Like

I am unable to find the corresponding names of subcategories. I have tried to parse the full response of GET request on /categories.json and I don’t see any field which gives me subcategory Name.

thanks for the reply. looking at the reverse engineer guide doesn’t really help me to be honest as I think some magic is going on here.

would you be able to pinpoint how the subcategory names are rendered from that JSON response? I am also not seeing any relevant subsequent calls that could potentially resolve those ids to actual names. The goal is to create a list of categories and subcategories which I can then position freely with custom markup. any help is appreciated.

I wonder if discourse/create-pretender.js at 928f1025166681105084a46ee733bfb08ca8d5e4 · discourse/discourse · GitHub create-pretenders are in play here to magically resolve names?

answering my own question here…

all categories of a site are listed in /sites.json. so you can use /catgories_and_latest for them main level categories and when you get across the subcategories ids for each main category you pick the subcategory name from the /sites.json response.

I assume there are some props in sites.json that identify a category as main or parent category so in the end /sites.json might be sufficient (one request). haven’t tested yet.