With the rapid development of computer science, there is an increasing demand for the use of causal inference methods and machine learning in the research of endocrine disorders and their long-term health outcomes. However, studies on the effective and appropriate applications of these approaches in real-world data and clinical settings are still limited. This review will illustrate the use of causal inference and machine learning in epidemiological research within the field of endocrinology and metabolism. It will examine each concept of causal inference and machine learning through application examples of endocrine disorders. Subsequently, the paper will discuss the integration of machine learning within the causal inference framework, including (i) the estimation of treatment effects or the causal relationship between exposure and outcomes, and (ii) the evaluation of heterogeneity in such treatment effects (or exposure-outcome causal relationship) based on individuals' characteristics. Accurately assessing causal relationships and their heterogeneity across different individuals is crucial not only for determining effective interventions, but also for the appropriate allocation of medical resources and reducing healthcare disparities. By illustrating some application examples in endocrinology, this review aims to enhance readers' understanding and application of causal inference and machine learning in future epidemiological studies focusing on endocrine disorders.