Skip to main content

Javascript

Javascript Example

The following example requests a quote for Home Insurance, and a quote for Auto Insurance. It then polls for a period of time before printing out the quotes that were returned by carriers.

Javascript Client Example
let baseUrl = '<insert-environment-url>';
let subscriptionKey = '<your-subscription-key-here>';

const MaxRetryValues = 10;

let autoResult = generateAutoQuotes({
"firstName": "Jake",
"lastName": "Ward",
"dateOfBirth": "1990-05-29",
"email": "test@test.com",
"phone": "541 754 3010",
"campaignCode": "MAGIC",
"productData": {
"address": {
"streetNumber": "1434",
"addressLine1": "Appleton Avenue",
"addressLine2": "",
"apartmentNumber": "6b",
"city": "Orlando",
"county": "Orange County",
"state": "FL",
"zip": "32806"
},
"gender": "Male",
"drivers": [
{
"firstName": "Jake",
"lastName": "Ward",
"licenseStatus": "PersonalAuto",
"licenseObtainedAge": "17",
"licenseEverSuspendedOrRevoked": false,
"sr22Required": false,
"gender": "Male",
"dateOfBirth": "1980-10-01",
"maritalStatus": "Single",
"occupation": "Architect",
"educationLevel": "SomeHighSchool",
"relationshipToApplicant": "Insured",
"violations": [
{
"violationDate": "2020-01-01",
"type": "CellPhone"
}
],
"claims": [
{
"claimDate": "2022-06-01",
"amount": "450",
"type": "Wing mirror"
}
]
}
],
"vehicles": [
{
"vin": "19XFC1F84HE004530",
"year": "2023",
"make": "Honda",
"model": "Civic",
"subModel": "Type R",
"primaryUse": "Personal",
"garageType": "AttachedGarage",
"parkedAtMailingAddress": true,
"garagingAddress": {
"streetNumber": "1434",
"addressLine1": "Appleton Avenue",
"addressLine2": "",
"apartmentNumber": "6b",
"city": "Orlando",
"county": "Orange County",
"state": "FL",
"zip": "32806"
},
"oneWayDistance": "17",
"annualMileage": "10000",
"ownership": "Leased",
"coveragePackage": "Basic"
}
],
"maritalStatus": "Married",
"yearsAtCurrentAddress": "10",
"homeOwnership": "OwnedHouse",
"creditRating": "Excellent",
"bankruptcy": false,
"currentCarrier": "Progressive",
"currentInsuranceExpirationDate": "2023-05-09",
"currentInsuranceYears": "TenOrMoreYears",
"bodilyInjuryLiabilityLimit": "BI_100000_300000"
},
"metadata": {
"TestKey1": "TestValue1",
"TestKey2": "TestValue2"
}
}).then(parseResponseData);

generateHomeQuotes({
"firstName": "Jake",
"lastName": "Ward",
"dateOfBirth": "1990-05-29",
"email": "test@test.com",
"phone": "541 754 3010",
"campaignCode": "MAGIC",
"productData": {
"address": {
"streetNumber": "1434",
"addressLine1": "Appleton Avenue",
"addressLine2": "",
"apartmentNumber": "6b",
"city": "Orlando",
"county": "Orange County",
"state": "FL",
"zip": "32806"
},
"gender": "Male",
"propertyPurchasedInLastSixMonths": true,
"previousAddress": {
"streetNumber": "1200",
"addressLine1": "Appleton Avenue",
"addressLine2": "",
"apartmentNumber": "",
"city": "Orlando",
"county": "Orange County",
"state": "FL",
"zip": "32806"
},
"propertyDetails": {
"propertyType": "SingleFamily",
"residenceUsage": "PrimaryResidence",
"yearBuilt": "2018",
"squareFootage": "3050",
"roofMaterial": "StandardShingle",
"bedrooms": "2",
"bathrooms": "2",
"marketValue": "125000",
"fireAlarm": "Local",
"burglarAlarm": "CentrallyMonitored",
"gatedCommunity": false
},
"carrier": "Progressive",
"coverageYears": "5",
"rating": "Good"
},
"metadata": {
"TestKey1": "TestValue1",
"TestKey2": "TestValue2"
}
}).then(parseResponseData);

function parseResponseData(data)
{
let autoQuoteCorrelationId = data.payload.quotesCorrelationId;

let currentAutoRetryCount = 0;
let autoQuoteData = {};
retrieveAutoQuotes();

function retrieveAutoQuotes() {
retrieveQuotes(autoQuoteCorrelationId).then(retrievedata => {
autoQuoteData = retrievedata;

if (currentAutoRetryCount <= MaxRetryValues) {
currentAutoRetryCount++;
setTimeout(retrieveAutoQuotes, 3000);
}
else {

for (const quote of autoQuoteData.payload.quotes) {
console.log(quote.carrierName + ' - '+ quote.premiumDetails.monthlyPremiumEstimate + ' for ' + quote.premiumDetails.termInMonths + ' months');
}
}
});
}
}

async function generateAutoQuotes(data = {}) {
console.log('Requesting auto quotes');
const rawResponse = await fetch('https://api-dev.simplyioa.com/quoting/v3/quotes/auto/request', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'subscription-key': subscriptionKey
},
body: JSON.stringify(data)
})
return rawResponse.json();
}

async function generateHomeQuotes(data = {}) {
console.log('Requesting home quotes');
const rawResponse = await fetch('https://api-dev.simplyioa.com/quoting/v3/quotes/home/request', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'subscription-key': subscriptionKey
},
body: JSON.stringify(data)
})
return rawResponse.json();
}

async function retrieveQuotes(quoteCorrelationId) {
const rawResponse = await fetch('https://api-dev.simplyioa.com/quoting/v3/quotes/' + quoteCorrelationId, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'subscription-key': subscriptionKey
}
})
return rawResponse.json();
}