public static PullRequestModel PullPayments(QueryPullAPIModel request, string ConsumerKey, string ConsumerSecret) { //var serializer = new JavaScriptSerializer(); string serializedBodyRequest = JsonConvert.SerializeObject(request); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(CONSTANTS.PullAPIQuery); httpRequest.ContentType = "application/json"; httpRequest.Method = "POST"; httpRequest.Headers.Add("Authorization", "Bearer " + PullAPIHttp.GetAuthen(ConsumerKey, ConsumerSecret)); using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream())) { streamWriter.Write(serializedBodyRequest); streamWriter.Flush(); streamWriter.Close(); } try { HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); var result = ""; using (var responseStream = new StreamReader(httpResponse.GetResponseStream())) { result = responseStream.ReadToEnd(); } PullRequestModel resp = JsonConvert.DeserializeObject <PullRequestModel>(result); Console.WriteLine("" + request.ShortCode + " " + resp.ResponseCode + " " + resp.ResponseMessage); if (resp == null) { Console.WriteLine("An error has occurred"); } if (resp.ResponseCode == "1000") { PullAPISQL.ProcessPulledPayments(resp, request.ShortCode); PullAPISQL.UpdateTillFetch(request, resp.Response[0].Count); } else { PullAPISQL.UpdateTillFetch(request, 0); } Console.WriteLine(resp.ToString()); return(resp); } catch (Exception ex) { Console.WriteLine(ex.ToString()); // Console.ReadLine(); return(null); } }