Fix bug in pulling data in api and store to database