Is it written anywhere in Ramayana that Ravana failed to defeat Nivatakavacha and Kalakeyas? If it is true then can you give me link of that section?
No, there is no mention in Valmiki Ramayana that Ravana has been defeated by either Kalakeyas or Nivatakavachas. In fact, there is no mention of Nivatakavachas in Valmiki Ramayana. Though there is mention of Kalakeyas who have been defeated by Ravana. Ravana defeating Kalakeyas has been mention in Valmiki Ramayana, Uttara Kanda, Chapter 29.
Thereat that Rakshasi, having blood red eyes, closed with tears, said "O king, by thee, powerful as thou art, I have forcibly been made a widow. Fourteen thousand Daityas, under the name of Kalakeyas, have been destroyed by thee, O king, in the battle and amongst them was my highly power ful husband dearer than my life. He has been slain by thee, O dear one, an enemy a brother only in name.
Yes, it is written in Valmiki Ramayana that Ravana failed to defeat Nivatakavachas. He fought for one year with Nivatakavachas and could not defeat them.
The story is mentioned in UTTARA KANDA of Valmiki Ramayana, after defeating Vasuki and before the war with Varuna (or his sons), Ravana had a war with Nivatakavachas:
And arriving at Bhogavati the city governed by Vasuki, he brought the Nagas under subjection.
And then, delighted, bent his course to the palace Manimayi There dwelt the Nivatakavachas, who had obtained boons. Those Daityas were possessed of prowess and endowed with strength, carrying various weapons, breathing high spirits and invincible in battle.
And the Danavas and Rakshasas growing enraged fell to raving each other with darts and tridents, Kulicas and axes and Patticas. And as they fought one entire year passed away and neither side obtained victory or was worsted.
And then that way of the triune sphere, that God, the undeteriorating Great father, swiftly presented himself on the scene mounted on his excellent car. And making the Nivatakavachas desist from battle the ancient great father (Lord Brahma) spoke in clear words:
"Even the Devas and the Asuras are not able to vanquish this Ravana in battle; nor can the Danavas backed by the Devas can destroy you (Nivatakavachas). Do you therefore turn your minds to making friends with the Rakshasa. All interests are forsooth the common possession of friends."
Thereat Ravana made friends with the Nivatakavachas in the presence of Fire ;and then rejoiced greatly.
This was one of the special cases of boon conflicts as discussed in Is there any mention of boon deadlock in scriptures? post.
Though, Ravana could defeat Kalakayas:
Ravana And then going to the city named Asma ruled by the Kalakayas, Ravana() slew the Kalakayas endowed with terriffic striength. ~UTTARA KANDA of Valmiki Ramayana