calling api on window.onload