Re: Response 200 but received code CDI001 (Bad Request)

Solved! Go to solution
alaneng
Helper

Response 200 but received code CDI001 (Bad Request)

Hello there, I gave up on the Python sample code and decided to go with the requests library to call the merchant measurement API. The API heavens granted me a 200 response status, but the response also ironically indicated code CDI001 - Bad Request.

 

Here's my code:

 

import requests

 

user_id = visa_api_user
password = visa_api_pass


url = 'https://sandbox.api.visa.com/merchantmeasurement/v1/merchantbenchmark'

 

body = {}

 

r = requests.post(url,
cert = ('/path/to/your/cert.pem', '/path/to/your/key....pem'),
auth = (user_id, password))

 

print(r.text)

 

I got back 

Connection {"error":{"code":"CDI001","message":"Bad Request"}}

which the documentation indicates is "Internal service failure". I'd appreciate any help!

8 REPLIES 8
API_Managers
Visa Developer Support Specialist

Re: Response 200 but received code CDI001 (Bad Request)

Hi @alaneng,

 

To further investigate, 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.

 

 




Thanks,

Tee



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

alaneng
Helper

Re: Response 200 but received code CDI001 (Bad Request)

Hi Diana,

I appreciate your reply, here's what I have:

 

1. End Point 

https://sandbox.api.visa.com/merchantmeasurement/v1/merchantbenchmark


2. Request Header

{}


3. Request Body

{}


4. Response Header (include the x-correlation-id)

 

5. Response Body

API_Managers
Visa Developer Support Specialist

Re: Response 200 but received code CDI001 (Bad Request)

Hello @alaneng,

 

Can you please make sure you are using the right credentials, such as username and password?

 

In addition to that, the issue could also be caused by the Certificates not being sent with the request. Check File->Settings->SSL Settings and make sure the KeyStore and KeyStore Password are populated in Soap UI.

SSL Settings Clientkeystore.png

 

The Certificate Signing Request is a prerequisite to get your application certificate (cert.pem), which is required to establish a two-way SSL connection. Additionally, you will need a root certificate (VICA-SBX.pem) and your private key.

 

You have two options to generate a Certificate Signing Request (CSR):

 

Have Visa generate a CSR for you
Select "generate a CSR from me" when you create a new Visa Developer application. When you select this option, Visa will generate a CSR for you, and you will be prompted to save your private key file when it is downloaded through your browser. Once you save your private key, go to your Visa app page and download your client certificate (cert.pem), as well as your root certificate (VICA-SBX.pem). You will then have everything you need to create a key store.

 

Generate your own CSR
You can choose to create your own CSR. The Visa Developer Getting Started Guide provides detailed steps on how to generate CSRs: https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl. Please note that you have to fill out all required fields in your Certificate Request. Also, note that the organization name and unit fields do not accept punctuation characters – your CSR will be deemed invalid if you use these characters. Once you have a CSR file, go ahead and create a Visa app, choose "Submit my own CSR", and upload your CSR file. During the CSR creation process, take note of the file containing your private key. Once you upload your CSR, go to your Visa app page, and download your client certificate (cert.pem), as well as your root certificate (VICA-SBX.pem). You will then have everything you need to create a key store.

 

Continuing to the Key Store
Once you have a private key and two certificate files in your local directory, you will need to combine them into a key store. You can decide whether to use Java Key Store (JKS) or PKCS (P12) key store, depending on what your development environment requires. There are sections in “Getting Started with Visa Developer” > “Two-Way SSL (Mutual Authentication)” (https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl), that describe how to create each type of key store, please follow those steps. Note, that the root certificate is not needed for a P12 file, you can create a P12 file out of two files: private key and cert.pem

 

Bad Request Error and Response Codes Table.png

 

 

Learn more about common Visa Developer error codes and how to resolve them using this link - https://developer.visa.com/pages/visa-developer-error-codes

 

If you continue to get this issue, please provide us the correlation ID and we can further investigate the issue.

Below are the steps to get the Correlation ID using a Google Chrome browser.
1>Open Chrome menu.
2>Click on More tools then Developer tools.
3>Check the box to Preserve Log for the Network Tab.
4>Click on the error and go to the Headers.
5>You can find the Correlation ID in the network log.

 

Please perform these steps and let me know your findings.

 

 




Thanks,

Tee



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

alaneng
Helper

Re: Response 200 but received code CDI001 (Bad Request)

Thank you for the detailed response Diana, it's not an issue with username/password because if I intentionally enter an incorrect password, the response would tell me the credentials are incorrect. Is there any way to verify if the certificates are being programmatically sent with the request instead of using a GUI? I'm using Python and would prefer this method over using a GUI. In another thread, I indicated I followed the Python sample code, but you replied the sample code is incorrect, so I'm trying to access the API using the `requests` library. Thank you!
API_Managers
Visa Developer Support Specialist

Re: Response 200 but received code CDI001 (Bad Request)

Hi @alaneng,

 

Yes, you can use the sample code to verify if the certificates are being programmatically sent with the request, instead of using a GUI. Please note, that the current Python Sample code has an issue and we are currently working on a fix.  

 




Thanks,

Tee



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

alaneng
Helper

Re: Response 200 but received code CDI001 (Bad Request)

Thanks, I think I'm getting pretty close. I created the key store using cert.pem and my private key .pem, but I fail to notice where to include the bundle in the Python sample code your website shows on the very bottom section of this page: https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl#sample_code_for_twoway_mutual_ss...

 

Referring to the screenshot in your previous image, it shows reasons for why one might receive a 400 Bad Request. However, I received a 200 status code coupled with the message Bad Request, so I don't know if those reasons in the screenshot are applicable to me. 

 

Where do I include the P12 bundle in the Python sample code of the Two Way Mutual SSL page? (Note I am not referring to the other Python sample code provided from the API, which I'm assuming you guys are working on fixing.) 

alaneng
Helper

Re: Response 200 but received code CDI001 (Bad Request)

Never mind, I got it to work. The takeaway is that the P12 bundle did *not* need to be included in the request. Here's the complete code that worked for me for anyone else who had trouble with this. Note that your DigiCertGlobalRootCA.crt needs to be converted to DigiCertGlobalRootCA.pem via this line:

 

openssl x509 -inform der -in DigiCertGlobalRootCA.crt -outform pem -out DigiCertGlobalRootCA.pem

 

Then input the filepath of your new DigiCertGlobalRootCA.pem file into the code below:

 

r = requests.post('https://sandbox.api.visa.com/merchantmeasurement/v1/merchantbenchmark',
verify = '/path/to/your/DigiCertGlobalRootCA.pem',
cert = ('/path/to/your/cert.pem', '/path/to/your/privateKey.pem'),
auth = (your_user_id, your_password),
json = {"requestData": {
"naicsCodeList": [
""
],
"merchantCategoryCodeList": [
"5812"
],
"merchantCategoryGroupsCodeList": [
""
],
"postalCodeList": [
""
],
"msaList": [
"7362"
],
"countrySubdivisionList": [
""
],
"merchantCountry": "840",
"monthList": [
"201706"
],
"accountFundingSourceList": [
"ALl"
],
"eciIndicatorList": [
"All"
],
"platformIDList": [
"All"
],
"posEntryModeList": [
"All"
],
"cardPresentIndicator": "CARDPRESENT",
"groupList": [
"STANDARD"
]
}
}

)

API_Managers
Visa Developer Support Specialist

Re: Response 200 but received code CDI001 (Bad Request)

Hi @alaneng,

 

Thanks for sharing the solution with us!   🙂

 

Can you please confirm if you are still having any issues with the Python sample code at this time? If you confirm that you are no longer experiencing any issues with Python, then I will close out any open Python sample code tickets that you may have open with us. Thanks!

 

 

 

 




Thanks,

Tee



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.