COF api error

Solved! Go to solution
arwani
Regular Visitor

COF api error

Here is the code, (I removed the pass)

import datetime
import json
import logging
import requests


# DEBUG = False
DEBUG = True


# Sample Code for Two-Way (Mutual) SSL

# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPSConnection.debuglevel = 0

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

print("START Sample Code for Two-Way (Mutual) SSL")

print(datetime.datetime.now())
date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")

url = "https://sandbox.api.visa.com/cofds-web/v1/datainfo"
headers = {"Content-Type": "application/json; charset=utf-8"}
body = {}

payload = json.loads(
""" {
"requestHeader": {
"requestMessageId": "6da6b8b024532a2e0eacb1af58581",
"messageDateTime": "2019-02-35 05:25:12.327"
},
"requestData": {
"pANs": [
4072208010000000
],
"group": "STANDARD"
}
}"""
)


# THIS IS EXAMPLE ONLY how will user_id and password look like
# user_id = '1WM2TT4IHPXC8DQ5I3CH21n1rEBGK-Eyv_oLdzE2VZpDqRn_U'
# password = '19JRVdej9'

user_id = "Hidden"
password = "Hidden"

# THIS IS EXAMPLE ONLY how will cert and key look like
# cert = 'cert.pem'
# key = 'key_83d11ea6-a22d-4e52-b310-e0558816727d.pem'

cert = "./cert.pem"
key = "./key_fae43842-1356-417a-9c2a-e2efb0861e40.pem"

timeout = 10

try:
response = requests.post(
url,
verify="./DigiCertGlobalRootCA.pem",
cert=(cert, key),
# headers = headers,
auth=(user_id, password),
# data = data,
json=payload,
timeout=timeout
# if DEBUG: print (response.text)
)
except Exception as e:
print(e)

if DEBUG:
print(response.headers)
if DEBUG:
print(response.content)

var1 = str(response.status_code)
var2 = "200"
msg = " Two-Way (Mutual) SSL test failed"
assert var1 == var2, msg
print("END Sample Code for Two-Way (Mutual) SSL\n\n")

 

============================================== (the response)

 

START Sample Code for Two-Way (Mutual) SSL
2022-08-28 22:34:12.677005
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): sandbox.api.visa.com:443
DEBUG:urllib3.connectionpool:https://sandbox.api.visa.com:443 "POST /cofds-web/v1/datainfo HTTP/1.1" 400 130
{'Server': 'nginx', 'Date': 'Sun, 28 Aug 2022 19:34:13 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '130', 'Connection': 'keep-alive', 'X-SERVED-BY': '-74979967r8', 'X-CORRELATION-ID': '1661715252_977_1521811976_-74979967r8_VDP_WS', 'X-ERROR-ORIGIN': '9200', 'X-APP-STATUS': '400', 'X-Frame-Options':
'SAMEORIGIN', 'X-XSS-Protection': '0', 'X-Content-Type-Options': 'nosniff', 'Strict-Transport-Security': 'max-age=31536000;includeSubdomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '-1', 'Content-Security-Policy-Report-Only': "default-src 'self' https://*.v.me https://*.visa.com;script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.visa.com https://*.v.me;img-src 'self' https://*.v.me https://*.visa.com https://*.unica.com https://ad.doubleclick.net;style-src 'self' 'unsafe-inline' https://*.visa.com;object-src https://*.v.me https://*.visa.com data:;report-uri /logging/logCSPReport;", 'X-Content-Security-Policy-Report-Only': "default-src 'self' https://*.v.me https://*.visa.com;script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.visa.com https://*.v.me;img-src 'self' https://*.v.me https://*.visa.com https://*.unica.com https://ad.doubleclick.net;style-src 'self' 'unsafe-inline' https://*.visa.com;object-src https://*.v.me https://*.visa.com data:;report-uri /logging/logCSPReport;", 'X-WebKit-CSP-Report-Only': "default-src 'self' https://*.v.me https://*.visa.com;script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.visa.com https://*.v.me;img-src 'self' https://*.v.me https://*.visa.com https://*.unica.com https://ad.doubleclick.net;style-src 'self' 'unsafe-inline' https://*.visa.com;object-src https://*.v.me https://*.visa.com data:;report-uri /logging/logCSPReport;"}
b'{"responseStatus":{"status":400,"code":"9125","severity":"ERROR","message":"Expected input credential was not present","info":""}}'
Traceback (most recent call last):
File "c:\Users\Arwani\Desktop\VISA\firstTry\test.py", line 97, in <module>
assert var1 == var2, msg
AssertionError: Two-Way (Mutual) SSL test failed

 

 

 

================================================

What should I do? I am pretty sure of my certificates and passwords.

5 REPLIES 5
jenn_kh
Community Moderator

Re: COF api error

Hi, @arwani! Thank you for reaching out to the community. Our agent is looking for a solution for you and will get back to you shortly. If any community members are able to assist, please feel free to reply here. -Jenn

I_Doroteo3
Visa Developer Support Specialist

Re: COF api error

Hi @arwani

 

Apologies for the late reply, 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.  

 

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/vdpguide#twowayssl. 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” ->“Using two-way SSL” (https://developer.visa.com/vdpguide#twowayssl), 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 

 

If you are still getting an error please feel free to contact us and provide the information listed below and please provide more information on the error you have received to Developer@visa.com. Please send the response request of the error received, screenshot and the Correlation ID. Some of this information should be kept private and that's the reason why I'm requesting you email your Correlation ID to Developer@visa.com. 

 

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>Then try to click on the add API link. 

5>You can find the Correlation ID in the network log for add API call. 

 

Please perform these steps and let me know your findings. 

 

Thanks, 

Illana

arwani
Regular Visitor

Re: COF api error

Hi @I_Doroteo3 ! Thanks for replying. Thankfully I have resolved the issue. It turned out that I was missing an important step which is MLE verification. It is a mandatory layer of security for the COF API. After implementing MLE I finally got the 200 success code.
gregbowers
Helper

loRe: COF api error

Hello

Ensure your request payload contains all required data, and verify the correctness of user credentials, certificates, and keys. Double-check the API endpoint URL. Handle exceptions gracefully and reach out to the API provider's support if needed for specific insights into the error. Thorough testing is essential to debug SSL issues effectively.

API_Managers
Visa Developer Support Specialist

Re: loRe: COF api error

HI @gregbowers,

 

Great advice! 😀 




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.