Endometriosis (EMS) is a prevalent gynecological disease that leads to chronic pelvic pain and infertility in women of reproductive age. However, the underlying pathogenic genes and effective treatment for EMS remain unclear. Therefore, this study aims to identify key genes influencing the diagnosis and treatment of EMS. The GSE7307 dataset, comprising 18 EMS and 23 control samples, was obtained from the GEO database. Fourteen differential genes related to NOD-like receptor protein 3 (NLRP3) activation and EMS were extracted from endometrial samples in GSE7307 through differential analysis. GO and KEGG analyses revealed that these genes were primarily involved in the production and regulation of the cytokine IL-1β and the NOD-like receptor signaling pathway. Random Forest (RF) and support vector machine recursive feature elimination algorithms were employed to select four diagnostic markers related to NLRP3 activation (NLRP3, IL-1β, LY96, and PDIA3) for constructing the EMS diagnostic model. These markers were validated using western blotting and tested in GSE7305 and GSE23339 datasets. The AUC values demonstrated the model's robust diagnostic performance. Additionally, the infiltration of immune cells in the samples and the correlation between different immune factors and diagnostic markers were explored. These results suggest that the four diagnostic markers may also play a crucial role in EMS immunity. Finally, the DrugBank database indicated that niclosamide could be effective for NLRP3-targeted therapy. In conclusion, we identified four key diagnostic genes for EMS, and niclosamide emerged as a potential drug for NLRP3-targeted therapy in EMS.