Facing Token Validation Failed in Helloworld api

saisandeep
New Contributor

Facing Token Validation Failed in Helloworld api

Facing an issue in helloworld api only
{
"responseStatus": {
"status": 401,
"code": "9159",
"severity": "ERROR",
"message": "Token Validation Failed",
"info": ""
}
}

Here i am trying to create a x-pay token 

var resourcePath = 'helloworld';
var queryParams = 'apiKey=QM6BVPJH6XNA7RMZGLJG21iNon2ZUrYEA5CDL3sTmKb_-7Xzk';
var sharedSecret = 'UJ8qGPUcz{H2gL1YPUMnaXUIJaMbVp2asi0U6w$3';
var postBody = '';

var timestamp = Math.floor(Date.now() / 1000);  
var preHashString = timestamp + resourcePath + queryParams + postBody;  
var hashString = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(preHashString, sharedSecret));
var xPayToken = 'xv2:' + timestamp + ':' + hashString;

postman.setEnvironmentVariable('x-pay-token', xPayToken);

Please let me know the issue 
5 REPLIES 5
jenn_kh
Community Moderator

Re: Facing Token Validation Failed in Helloworld api

Hi @saisandeepThank you for reaching out. One of our agents will look into this and get back to you soon. If any community member knows a solution, please feel free to reply to this thread.

saisandeep
New Contributor

Re: Facing Token Validation Failed in Helloworld api

Hi, No Agent is assigned. Its been almost two weeks now and none of the support team has reached out to us.

diana658
Newbie

Re: Facing Token Validation Failed in Helloworld api


@saisandeepbcbsfl wrote:

Facing an issue in helloworld api only
{
"responseStatus": {
"status": 401,
"code": "9159",
"severity": "ERROR",
"message": "Token Validation Failed",
"info": ""
}
}

Here i am trying to create a x-pay token 

var resourcePath = 'helloworld';
var queryParams = 'apiKey=QM6BVPJH6XNA7RMZGLJG21iNon2ZUrYEA5CDL3sTmKb_-7Xzk';
var sharedSecret = 'UJ8qGPUcz{H2gL1YPUMnaXUIJaMbVp2asi0U6w$3';
var postBody = '';

var timestamp = Math.floor(Date.now() / 1000);  
var preHashString = timestamp + resourcePath + queryParams + postBody;  
var hashString = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(preHashString, sharedSecret));
var xPayToken = 'xv2:' + timestamp + ':' + hashString;

postman.setEnvironmentVariable('x-pay-token', xPayToken);

Please let me know the issue 

Hello, @saisandeep 

 

Please see below information and follow.,

 

// Resource path for the API endpoint
var resourcePath = 'helloworld';

// Query parameters with the API key
var queryParams = 'apiKey=QM6BVPJH6XNA7RMZGLJG21iNon2ZUrYEA5CDL3sTmKb_-7Xzk';

// Shared secret provided by the API service
var sharedSecret = 'UJ8qGPUcz{H2gL1YPUMnaXUIJaMbVp2asi0U6w$3';

// Post body for the API call (if any)
var postBody = '';

// Current timestamp in seconds
var timestamp = Math.floor(Date.now() / 1000);

// Concatenating the required elements for hashing
var preHashString = timestamp + resourcePath + queryParams + postBody;

// Generating the HMAC SHA256 hash of the pre-hash string
var hashString = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(preHashString, sharedSecret));

// Creating the x-pay token
var xPayToken = 'xv2:' + timestamp + ':' + hashString;

// Setting the x-pay token in the environment variable
postman.setEnvironmentVariable('x-pay-token', xPayToken);

 

I hope my suggestion is helpful for you.

 

Best Regard,
diana658

saisandeep
New Contributor

Re: Facing Token Validation Failed in Helloworld api

Still i am getting the same error. 

API_Managers
Visa Developer Support Specialist

Re: Facing Token Validation Failed in Helloworld api

Hi @diana658,

 

Please visit the Visa Developer Error Codes page for cause/resolution. 




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.