Iraq "had" (and still has) a capital of Baghdad Province. That capital "was" (and still is) Baghdad City. Or were you trying to ask "What country is Baghdad the capital of"? In which case the answer would be; The capital city of Iraq is Baghdad.
Baghdad was the capital of the ABBASSID CALIPHATE and was one of the centers of the Islamic Golden Age. It was most notable for its massive library called Beit al-Hikma (بيت الحكمة) or the House of Wisdom. After the Mongols razed Baghdad in 1258, the city lost most of its importance.
The Abbassids moved their capital to Baghdad because their base of support was among the Persians and Mesopotamian Arabs (as opposed to Damascus, which was the base of support for their Umayyad rivals).
Damascus was the capital of the Uymmad Caliphate, the caliphate before the Abbasid one. The first capital of the Abbasid Caliphate was Kufa, then Baghdad, then Samarra, and then Baghdad once more (all four cities located in Iraq).