Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am trying to fix a payment Api, I am getting 400 error message, saying that one or more validation issues. What could be my mistake?
below is my code.

var client = new RestClient("https://sandbox-api-d.squadco.com/transaction/initiate");
            
            var keyValues = new Dictionary<string, string>
                            {
                                { "amount", "10000"},
                                { "email" , abc@mail.com},
                                { "currency", "NGN"},
                                { "initiate_type", "inline"},
                                { "transaction_ref" , "34532756YT"},
                                { "callback_url", "https://samplesite.com"}                        
                            };
            
            string JsonBody = JsonConvert.SerializeObject(keyValues);

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


What I have tried:

I tried running the code in postman, and it worked fine.
Posted
Updated 11-Dec-22 4:54am
v2

1 solution

Look at your code: it doesn't compile.

You declared keyValues as a Dictionary<string, string> but then try to pass it a number of values that aren't strings: 10000, abc@mail.com, 34532756YT
Change those to strings, and it might compile, which will start you towards the next step:
var keyValues = new Dictionary<string, string>
                {
                    { "amount", "10000"},
                    { "email" , "abc@mail.com"},
                    { "currency", "NGN"},
                    { "initiate_type", "inline"},
                    { "transaction_ref" , "34532756YT"},
                    { "callback_url", "https://samplesite.com"}
                };
Or fix the Dictionary so it accepts the right types of value ...
 
Share this answer
 
Comments
Mekadosky 11-Dec-22 10:53am    
I fixed the strings, and tried again, I still get the 400 error code, still saying "one or more validation error occurred". I can't really figure out where the problem is...
OriginalGriff 11-Dec-22 11:35am    
Since your original code didn't even compile, and you are still getting exactly the same error message, I'd suggest that you need to make sure that you code does compile - i.e. has no other errors preventing an EXE file being created - and that you are executing the right version of the right assembly.
Because the best guess from this distance is that you aren't!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900