Don’t do that. You want to use an import script. You can look at discourse/script/import_scripts at main · discourse/discourse · GitHub for examples and search here for instructions for running import scripts for other forums.
Posts are displayed in the order in which they are created. So you’d need to have your API script (that you really don’t want to use) create them in the proper order.