Home > OS >  How to resolve 400 error code, "one or more validation error occurred"
How to resolve 400 error code, "one or more validation error occurred"

Time:12-12

I am trying to fix a payment Api using visual studio c#, but I am getting 400 error message, it says that one or more validation error occurred. please what could be my mistake? I tried running the code in postman, and it worked fine. Below is my code sample:

     public class Root
             {          
                 public string amount { get; set; }
                 public string email { get; set; }
                 public string currency { get; set; }
                 public string initiate_type { get; set; }
                 public string transaction_ref { get; set; }
                 public string callback_url { get; set; }
             }
        
        
        
     var client = new RestClient("https://sandbox-api-d.squadco.com/transaction/initiate");
        
                 var rootObj = new Root
                                 {
                                     amount = "1000",
                                     email = EmailV,
                                     currency = "NGN",
                                     initiate_type = "inline",
                                     transaction_ref = "213445RT",
                                     callback_url = "https://samplesite.com"                        
                                 };
                 //serialization using Newtonsoft JSON 
                 string JsonBody = JsonConvert.SerializeObject(rootObj);
        
                 var request = new RestRequest();
                 request.Method = Method.Post;
                 request.AddHeader("Authorization", "sandbox_sk_3fae7c45922315aa8cb2a16db028f50a596d5fbdf351");
                 request.AddHeader("Content-Type", "application/json");
                 request.AddParameter("application/json", JsonBody, ParameterType.RequestBody);
                 RestResponse response = client.Execute(request);

CodePudding user response:

Based on their doc, the amount is decimal

https://squadinc.gitbook.io/squad/payments/initiate-payment#sample-request

so you can try changing to decimal

                 var rootObj = new Root
                                 {
                                     amount = 1000,
  • Related