Hi and welcome.
You should be able to buy the ticket just at the station in Istanbul.
See here for details: rail.cc/en/train/istanbul-to-konya
Online tickets and schedules: rail.shop/tcdd
Select as destination "Konya YHT". It is also possible to buy a ticket Istanbul-Ankara and then Ankara-Konya.
There are three direct trains from Istanbul to Konya per day with a journey time of about 4:15h. Ticket starts from 85 TRY (= 14 EUR).