You should start a new topic for that and the question itself is too broad for a real answer, but you should have a look at Developing Discourse Plugins - Part 1 - Create a basic plugin and the rest. You’ll want to search for stuff about creating topic_custom_fields and adding them to the serializer. See GitHub - discourse/all-the-plugins to get all of the plugins and then you can search those for examples.
You might say more about what you’re doing that requires the custom fields, as there could be some other way to accomplish that task without custom fields and without a plugin.