Move API call to inside main function