Imported categories are not in parent category

AI-generated summary

AudeF is trying to duplicate a category structure (from version 26 to 27) by exporting and importing JSON files, but imported subcategories are not appearing under the intended parent category. They manually set the parent ID in the JSON but still encountered issues. NateDhaliwal asks if setting the parent category ID works, and AudeF confirms it’s working manually for now but seeks an automated solution. tobiaseigen requests more context — AudeF explains their forum is used to discuss annual software test versions with external users, and they create a new category per version to avoid mixing discussions. They want to automate the process to avoid manual work each year. AudeF also references a related topic for exporting/importing JSON files. The core issue is that subcategories are not respecting the parent ID during import, despite correct manual edits.

Hi all!

I’m trying to duplicate the structure of a category (copy all sub-categories from the previous version 26 to new version 27).

What I’m doing :

  • I create my new category 27, and note its id
  • I export a json with command discourse export_category 26
  • I edit the json file to keep only categories, I change the slugs to keep them unique, …
  • for each sub-category, I set “parent_category_id”: new category id

I then import my edited json with discourse import_category file.json

My sub-categories are then imported but NOT in my new category, they have no parent.

What is the right way to import in a category?

Does setting the parent in the category settings work?

Yes, the manual change is OK

@AudeF would you be able to explain in some more detail what your site is about and what you’re trying to do? Why do you need to duplicate the strucuture of a category and all its subcategories?

Can you also show your work in some more detail here, eg how exactly did you export the json and then import it again?

Some time has passed since you asked so perhaps in the meantime you’ve figured some things out?

Well, I’ve set the parent category manually, so it’s ok for now, but I’d like to not have to do it again next year :sweat_smile: .

We use our forum to discuss the tests of our software with external users. We have a new version each year, and we don’t want to mix new tests with older discussions, so we create a new category for each version. The sub-categories are mostly the same each time so I don’t want to create them by hand again and again :wink: .

I use this tutorial to export and import the json files: Move topics from one Discourse instance to another , except that I do it for the same forum so I change the slugs and ids to avoid conflicts.