// Get form fields
const { fname, lname, zip_code, address_street, day_dob, month_dob, year_dob, ipaddress } = feathery.getFieldValues();
// Format DOB
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const monthNumber = monthNames.indexOf(month_dob) + 1;
const formattedMonth = monthNumber < 10 ? `0${monthNumber}` : monthNumber;
const dob = `${year_dob}-${formattedMonth}-${day_dob}`;
// Fetch location data
fetch(`https://api.zippopotam.us/us/${zip_code}`)
.then(response => response.json())
.then(locationData => {
console.log(locationData);
const city = locationData.places[0]['place name'];
const state = locationData.places[0]['state abbreviation'];
// Send data to AWS Lambda function via API Gateway
fetch('https://d35osst22fm25k.cloudfront.net/api/arrayio', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-credmo-client-token': '0C083358-9D67-43CD-B2D7-895823D3AA0E'
},
body: JSON.stringify({
appKey: '426AD318-E154-4A27-8BEB-23859F5AC7C9',
firstName: fname,
lastName: lname,
dob: dob,
address: {
street: address_street,
city: city,
state: state,
zip: zip_code,
},
userConsent: {
ipAddress: ipaddress,
timestamp: new Date().toISOString(),
url: 'https://www.credit1finance.com',
},
productCode: 'offers-2005-decision-1',
}),
})
.then(response => response.json())
.then(data => {
// Extract higher value from credit score range
const creditScoreRange = data.results.credit_score;
const higherCreditScore = parseInt(creditScoreRange.split('-')[1]);
// Extract higher value from number_of_collections range
const collectionsRange = data.results.number_of_collections;
const higherNumberOfCollections = parseInt(collectionsRange.split('-')[1]);
// Populate Feathery Hidden fields
feathery.setFieldValues({
array_credit_score: higherCreditScore,
array_credit_utilization: data.results.credit_utilization,
array_number_of_repossessions: data.results.number_of_repossessions,
array_number_of_delinquencies: data.results.number_of_delinquencies,
array_number_of_collections: higherNumberOfCollections,
array_number_inquiries: data.results.number_inquiries,
array_number_accounts: data.results.number_accounts,
array_account_age: data.results.account_age,
array_monthly_payments: data.results.monthly_payments,
array_under_21: data.results.under_21,
array_totalUnsecuredDebt: data.results.totalUnsecuredDebt,
});
})
.catch(error => console.error('Error:', error));
});
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter