Creating new topic in subcategory via API

AI-generated summary

In a discussion about creating topics in subcategories via the Discourse API, nordize initially struggled using category slugs (e.g., subcategory-slug or category-slug/subcategory-slug), which defaulted topics to “uncategorized.” jomaxro suggested using the category name instead of the slug, citing a Meta Discourse thread. nordize later reported that using the category name (even with spaces, URL-encoded as + or %20) eventually worked after renaming the category to remove spaces — though reverting to a spaced name still functioned. cpradio pointed to the official API docs, which specify that the category parameter should be an integer (category ID), not a string. nordize confirmed that using the category name (string) did work for them, despite the docs. The thread highlights a discrepancy between documentation and observed behavior, with success ultimately achieved using category names, even with spaces, though the intended method per docs is the category ID.

I tried using &category=subcategory-slug but it ends up in the uncategorized category. I also tried to use &category=category-slug/subcategory-slug and got the same thing. It works fine if it’s a main category. Is it possible to create a new topic in a subcategory? If yes, what’s the syntax?

Assuming the API takes the same parameters as create topic via URL (no idea why it wouldn’t) - then you should be using the category name, not the slug.

Source:
https://meta.discourse.org/t/cannot-compose-a-pre-filled-topic-via-url-when-subcategory-has-topic-template/39941/2?u=jomaxro

I just wanted to reply to say that I tried the category name too and that failed too. It had spaces (I used the url encoded version with both + and %20) but now I renamed it to something without spaces and it works. I then renamed it back to something with spaces and it still works … sorry for wasting your time :confused:

Based on the docs, the category parameter is an integer, you need to use the category id there.

It certainly worked with the category name (string) though.