const express = require('express');
const fs = require('fs');
var https = require('https');
const request = require('request');
const app = express();
const bodyParser = require('body-parser')
var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(express.json());
app.use(bodyParser.urlencoded({extended: true}));
var username = '*********';
var password = '**********';
var cert = 'cert.pem';
var key = 'key.pem';
var data ={
"acquirerDetails": {
"bin": 408999,
"settlement": {
"currencyCode": "840"
}
},
"rateProductCode": "A",
"markupRate": "0.07",
"destinationCurrencyCode": "826",
"sourceAmount": "100.55",
"sourceCurrencyCode": "840"
};
app.get('/', (req, res) => {
var options = {
hostname: 'sandbox.api.visa.com',
port: 443,
uri: 'https://sandbox.api.visa.com/forexrates/v2/foreignexchangerates',
method: 'GET',
key: fs.readFileSync(key),
cert: fs.readFileSync(cert),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Basic ' + Buffer.from(username + ':' + password).toString('base64')
},
json: true
};
options.agent = new https.Agent(options);
request.post(options, (err, res, body) => {
if (err) {
return console.log(err);
}
console.log(`Status: ${res.statusCode}`);
console.log(body);
});
res.send(data);
});
app.listen(3050, function () {
console.log('Example app listening on port 3050.');
})
Hi @Soumith,
Please provide the following information:
Using SoapUI, you can find the x-correlation-id in the Raw Tab of the response header.
To learn more about common Visa Developer error codes and how to resolve them, please navigate to our Visa Developer Error Codes page here - https://developer.visa.com/pages/visa-developer-error-codes
If you don't find an error code listed here, please refer to the API-specific error codes in its respective documentation pages.
Thanks,
Illana
Status: 401
{ responseStatus:
{ status: 401,
code: '9159',
severity: 'ERROR',
message: 'Token Validation Failed',
info: '' } }
This is the error code i have been getting
Hi @Soumith,
Apologies for the late response- the 401 Token Validation Failed error you're getting will be seen when the x-pay-token sent in the header is invalid.
A couple of things I'd like you to note while generating the token:
Can you please provide the request payload of this API call? It's possible that you're missing a field or have an inaccurate format. I'd like to see screenshot attachments of the error provided, if possible.
Also, could you check to see if you're passing a correct value for URI. For example, make sure it’s defined correctly in the beginning of your code, and use the same value for the URI in the middle of your code. In general, for cases like this (i.e. “helloworld works, but the API XX doesn’t”) I'd like to ask of you, if you could, to please extend your SOAPUI project, and make sure that you can call a particular API from SOAPUI project first.
Thanks,
Illana