in Asp.net MVC Rest Api I Have Passed The Add Parameter but in Response It Said that the parameter is missing
There is an API That works properly in Postman But When I Execute the same API in the Asp.net MVC Project it gives me a missing parameter. Below is the Rest of the API Code.
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string Baseurl = "End Point URL";
var client = new RestClient(Baseurl + "billpay/customer-params");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Root-id", agentid);
request.AddHeader("Authorization", "Bearer " + token + "");
request.AddHeader("clientId", clientId);
request.AddHeader("ClientSecret", ClientSecret);
request.AddHeader("distributorCode", distributorCode);
request.AddHeader("content-type", "application/json");
request.AlwaysMultipartFormData = true;
request.AddParameter("agent", agentid);
request.AddParameter("billerid", billerid);
IRestResponse responsecheck = client.Execute(request);
return responsecheck;


Vishal JoshiRank #377 · 6.7K reputationPosted Feb 24, 2024, 8:32 AM EST
Hello Ajay
Try code with JSON Serialization. You should remove the headers and instead serialize the parameters into JSON format and add them to the request body.
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; string Baseurl = "End Point URL"; var client = new RestClient(Baseurl + "billpay/customer-params"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer " + token); request.AddHeader("content-type", "application/json"); // Assuming the parameters agentid and billerid are to be sent in the request body var requestBody = new { agent = agentid, billerid = billerid }; string jsonRequestBody = JsonConvert.SerializeObject(requestBody); request.AddParameter("application/json", jsonRequestBody, ParameterType.RequestBody); IRestResponse responsecheck = client.Execute(request); return responsecheck;Thanks
Ajay KumarRank #56 · 29K reputationPosted Feb 25, 2024, 12:41 AM EST
Thanks Buddy , Now The Problem Solved