public async Task <IActionResult> GetCup([FromRoute] string id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var cup = await _context.Cups.FindAsync(id); if (cup == null) { return(NotFound()); } int tmplimit; if (cup.limit != null) { tmplimit = Int32.Parse(cup.limit); } else { return(BadRequest(ModelState)); } int newLimit = tmplimit - 10; if (tmplimit > 10) { //call danske bank api var client = new RestClient("https://api.sandbox.mobilepay.dk/bindings-restapi/api/v1/payments/payout-bankaccount"); var request = new RestRequest(Method.POST); request.AddHeader("Postman-Token", "d8183387-6050-45d4-a047-aee929de826a"); request.AddHeader("cache-control", "no-cache"); request.AddHeader("x-ibm-client-secret", "L7yW0eV0eK5yX1nK4rO0lI8sX5aN2tL6aQ0sL7gM1xO6sW8kK1"); request.AddHeader("x-ibm-client-id", "1c0cd3ff-1143-476b-b136-efe9b1f5ecf3"); request.AddHeader("Content-Type", "application/json"); request.AddParameter("undefined", "{\n\t\"merchantId\" : \"35ed5788-51e3-4fd8-b7a3-020a9f7c8533\",\n\t\"merchantBinding\" : \"000\",\n\t\"receiverRegNumber\" : \"3098\",\n\t\"receiverAccountNumber\" : \"3100460793\",\n\t\"amount\" : 10\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); //if danskeAPI went okay we subtract the limit if (response.Equals(204)) { cup.limit = newLimit.ToString(); _context.Entry(cup).State = EntityState.Modified; _context.SaveChanges(); } } else { return(BadRequest(ModelState)); } Console.WriteLine(cup); return(Ok(cup)); }