coded the api request to database function