The first measurement of the impurity density profile via charge exchange spectroscopy (CES) has been successfully achieved in KSTAR. Since the neutral beam density profile is essential for the measurement, the neutral beam penetration code that was originally developed for the Alcator C-mod tokamak has been optimized for the KSTAR experimental environment. The method of the impurity density measurement by the KSTAR CES system is introduced and the sensitivity analysis of various physical parameters, such as the effective charge in the estimation of the impurity density, is performed to examine the validation of the method. This method has been applied to measure the C6+ density profile affected by the resonant magnetic perturbations (RMPs), which is mainly used to suppress the edge localized modes (ELMs) in KSTAR. The dynamics of the C6+ density profile represent that the C6+ density decreases immediately after the application of RMPs but recovers soon during the ELM-suppressed phase.& nbsp;& nbsp;(C) 2022 Author(s).All article content, except where otherwise noted, is licensed under a Creative Commons Attribution (CC BY)license (http://creativecommons.org/licenses/by/4.0/).