How to return an API response n times after calling it in python?

Solution
var x = 0;
var intervalID = setInterval(function () {

   // Your logic for calling api here

   if (++x === 4) { // call four times times
       window.clearInterval(intervalID);
   }
}, 10000);// 1 sec == 1000ms