Hey @jsfierro,
It appears that you are encountering a `400 Bad Request` error with the message "Expected input credential was not present" when trying to access the Forex Rates API. This error typically indicates that the API request is missing required authentication credentials or they are not properly formatted.
Here's a checklist to help troubleshoot and resolve the issue:
1. Authentication Credentials
Ensure that you are passing the correct authentication credentials in the request headers. For Visa APIs, you usually need to include the following headers:
- `Authorization`: This header should contain the Basic Auth credentials or OAuth token, depending on the authentication method used.
- `x-api-key`: This header should contain the API key provided to you when you registered your application on the Visa Developer Platform.
2. Request Headers
Make sure your request headers look something like this:
```http
Accept: application/json
Content-Type: application/json
Authorization: Basic YOUR_BASIC_AUTH_CREDENTIALS
x-api-key: YOUR_API_KEY
```
3. Request Body
Verify that your request body is correctly formatted as JSON and contains all the required fields. Your provided request body looks correct, but make sure the `initiatingPartyId`, `rateProductCode`, `destinationCurrencyCode`, and `sourceCurrencyCode` are valid:
```json
{
"initiatingPartyId": 1002,
"rateProductCode": "BANK",
"destinationCurrencyCode": "USD",
"sourceCurrencyCode": "EUR",
"quoteIdRequired": true
}
```
4. Example Code
Here’s an example of how you might structure your request using Node.js and the `axios` library:
```javascript
// START
const axios = require('axios');
const fs = require('fs');
const path = require('path');
// Read your certificate and key files
const cert = fs.readFileSync(path.resolve(__dirname, 'cert.pem'));
const key = fs.readFileSync(path.resolve(__dirname, 'key.pem'));
const requestHeaders = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Basic YOUR_BASIC_AUTH_CREDENTIALS',
'x-api-key': 'YOUR_API_KEY'
};
const requestBody = {
"initiatingPartyId": 1002,
"rateProductCode": "BANK",
"destinationCurrencyCode": "USD",
"sourceCurrencyCode": "EUR",
"quoteIdRequired": true
};
const requestConfig = {
method: 'post',
url: 'https://sandbox.api.visa.com/forexrates/v2/foreignexchangerates',
headers: requestHeaders,
data: requestBody,
httpsAgent: new https.Agent({
cert: cert,
key: key
})
};
axios(requestConfig)
.then(response => {
console.log('Response:', response.data);
})
.catch(error => {
console.error('Error:', error.response ? error.response.data : error.message);
});
// END
```
5. API Key and Credentials
Double-check that you are using the correct API key and credentials. If you are using Basic Auth, ensure that the credentials are base64-encoded properly.
6. Access Control
Ensure that your API key has the necessary permissions to access the Forex Rates API. You can verify this in the Visa Developer Portal under your project settings.
7. Endpoint URL
Ensure that you are using the correct endpoint URL. For the sandbox environment, it should be:
```
https://sandbox.api.visa.com/forexrates/v2/foreignexchangerates
```
Conclusion
By following the above steps, you should be able to address the "Expected input credential was not present" error. If you continue to face issues, please provide additional details, such as the exact method of authentication you are using, so that further assistance can be provided.