Token Validation Error VTS

Solved! Go to solution
Regular Visitor

Token Validation Error VTS

I'm trying to make an API call to COF data inquiry, but I'm getting the following error: {'responseStatus': {'status': 401, 'code': '9210', 'severity': 'ERROR', 'message': 'Token validation failed', 'info': ''}}
This is the code
import datetime
from distutils import debug
import time
import json
import ast
import logging
import requests
from jwcrypto import jwk, jwe

myKey_ID  = 'bf4e64ce-0e41-4a73-9a3d-f8ed8d25133a'
server_cert = 'server_cert_bf4e64ce-0e41-4a73-9a3d-f8ed8d25133a.pem'
private_key = 'key_bf4e64ce-0e41-4a73-9a3d-f8ed8d25133a.pem'

def encrypt(payload, server_cert, myKey_ID😞
    payload = json.dumps(payload)
    protected_header = {
            "alg": "RSA-OAEP-256",
            "enc": "A128GCM",
            "kid": myKey_ID,
            "iat": int(round(time.time() * 1000))
    jwetoken = jwe.JWE(payload.encode('utf-8'),
    encryptedPayload = jwetoken.serialize(compact=True)
    return {"encData": encryptedPayload}  

def decrypt(encPayload, private_key😞
    if type(encPayload) is str:
        payload = json.loads(encPayload)
    if encPayload.get('encData', True😞
        jwetoken = jwe.JWE()
        jwetoken.deserialize(encPayload["encData"], key=loadPem(private_key))
        return jwetoken.payload
    return encPayload


def loadPem(filePath😞
    with open(filePath, "rb") as pemfile:
        return jwk.JWK.from_pem(

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


date ="%Y-%m-%dT%H:%M:%S")



headers = { "content-type": "application/json",
            'accept': 'application/json',
            'keyId': myKey_ID


body = {}


payload = json.loads('''{ "requestHeader":{
      "messageDateTime":"'''+ date +'''"

user_id = 'RPNXAMSRCKPXKLZ1C42F21JX4aWTmPRVJT7l5RSJh9ts6r-6c'
password = 'r2AOqpk7nf0yZ6hKF3oYIIn7Vq'

cert = 'cert.pem'
key = 'key_974255ae-5455-486e-ac2c-a13630debe20.pem'


timeout = 10


encryptedPayload = encrypt(payload, server_cert, myKey_ID)

    response =,
                            cert=(cert, key),
                            headers = headers,
                            auth=(user_id, password),
                            json = encryptedPayload,
except Exception as e:

decryptedPayload = decrypt(response.json(), private_key)

data = ast.literal_eval(decryptedPayload.decode('utf8'))


print("Decrypted payload",data)

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

When I debug I get this


Sorry for the bad english and I would appreciate any type of help.I'm doing this for the visa virtual internship program and trying to learn as much as I can.

Community Moderator

Re: Token Validation Error VTS

We appreciate you bringing this to our attention, @mooaz624 . We have let our team know and an agent will follow up with any information. - Cathy

Regular Visitor

Re: Token Validation Error VTS

Ok thanks 🙏
Visa Developer Support Specialist

Re: Token Validation Error VTS

Hi @mooaz624


Because Visa Token Services is a restricted product, please reach out to your Visa Account Executive, Gateway or Acquiring partner, and/or visit our detailed Product page at Visa Ready.


You also can submit specific queries about the product through Visa Ready using the “Contact Us” link.




Regular Visitor

Re: Token Validation Error VTS

I'm sorry I probably didn't explain my problem well, but I'm trying to use the Card On File Data API because this is the task given to me in the visa virtual internship program. So just to make sure I understood correctly this is restricted? Because there was nothing said about it being restricted in the explanation of the task.
Regular Visitor

Re: Token Validation Error VTS

I figured out how to solve my problem it was my date and time settings. Thank you @I_Doroteo3 for the response and sorry for taking your time.

Re: Token Validation Error VTS

Ok thanks :folded_hands: