Solved! Go to Solution
Hey @Rossman,
I'm happy to help resolve the issue. My apologies for the delayed response. Can you please let me know which API you are trying to call? Can you share your request header and snapshots of the error?
Please try to resolve the issue by creating new .p12 using this command line
command line:
openssl pkcs12 -export -out p12certfile.p12 -inkey example-key.pem -in cert.pem
Create the certificate file ".p12" file using the openssl command I suggested.
Please try to test again and start by calling helloworld API from sandbox environment. "vdp/helloworld".
To resolve the issue, instead of using certificate file (.p12) in the code, install the certificate on the machine and let the Framework code load the certificate from certificate store and use it for API call.
With the above approach you'll be able to call the APIs successfully. Following is the sample to the final code that is working.
public string RequestHelloWorld()
{
string requestURL = "vdp/helloworld";
string userId = ConfigurationManager.AppSettings["userId"];
string password = ConfigurationManager.AppSettings["password"];
string apiResponse = "";
try
{
return PerformDualAuthCall(requestURL, HttpMethod.Get, null, null);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return apiResponse;
}
public string PerformDualAuthCall(string requestPath, HttpMethod method, object requestBody, Dictionary headers = null)
{
string requestURL = ConfigurationManager.AppSettings["visaUrl"] + requestPath;
string userId = ConfigurationManager.AppSettings["userId"];
string password = ConfigurationManager.AppSettings["password"];
string apiResponse = "";
try
{
if (headers == null)
{
headers = new Dictionary();
}
headers.Add(HttpRequestHeader.Authorization.ToString(), GetBasicAuthHeader(userId, password));
var httpClientHandler = new HttpClientHandler();
httpClientHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;
using (HttpClient httpClient = new HttpClient(httpClientHandler))
{
var request = new HttpRequestMessage
{
Method = method,
RequestUri = new Uri(requestURL)
};
if (headers != null)
{
foreach (var item in headers)
{
request.Headers.Add(item.Key, item.Value);
}
}
if (requestBody != null)
{
request.Content = new StringContent(requestBody is string ? requestBody as string : JsonConvert.SerializeObject(requestBody), Encoding.UTF8, "application/json");
};
// Make the call
var response = httpClient.SendAsync(request).Result;
if (response.StatusCode == HttpStatusCode.OK)
{
apiResponse = response.Content.ReadAsStringAsync().Result;
}
}
}
catch (HttpRequestException e)
{
Console.WriteLine(e.Message);
}
return apiResponse;
}
To learn more about common Visa Developer error codes and how to resolve them please go to our Visa Developer Error Codes page here - https://developer.visa.com/pages/visa-developer-error-codes
If there's an error code that you're looking for that's not listed here, please refer to the API-specific error codes in its respective documentation pages.
HTTP STATUS | HTTP CODE | CAUSE/RESOLUTION |
---|---|---|
BAD REQUEST |
400 |
This error could be due to a variety of reasons. Check for the following:
Or
Or
|
If the issue persists, please provide the following information:
1. End Point
2. Request Header
3. Request Body
4. Response Header (include the x-correlation-id)
5. Response Body
Using SoapUI, you can find the x-correlation-id in the Raw Tab of the response header.