简体   繁体   中英

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

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);

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM