Skip to main content

Javascript

Javascript Example

The following example calls both of the consumer journey Auto and Home Insurance APIs:

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

generateConsumerAutoJourney({
"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(data => {
console.log(data.payload.onlineJourneyUrl)
});

generateConsumerHomeJourney({
"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"
},
"propertyPurchasedInLastSixMonths": true,
"previousAddress": {
"streetNumber": "1200",
"addressLine1": "Appleton Avenue",
"addressLine2": "",
"apartmentNumber": "",
"city": "Orlando",
"county": "Orange County",
"state": "FL",
"zip": "32806"
},
"mortgageeLender": {
"companyName": "Mortgage Company",
"addressLine1": "1025 Appleton Avenue",
"addressLine2": "Business District",
"city": "Orlando",
"state": "FL",
"zip": "32806",
"loanNumber": "M123456"
},
"gender": "Male",
"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(data => {
console.log(data.payload.onlineJourneyUrl)
});

async function generateConsumerAutoJourney(data = {}) {
const rawResponse = await fetch(baseUrl + '/consumer-journey/v3/consumer-data/auto', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'subscription-key': subscriptionKey
},
body: JSON.stringify(data)
})
return rawResponse.json();
}

async function generateConsumerHomeJourney(data = {}) {
const rawResponse = await fetch(baseUrl + '/consumer-journey/v3/consumer-data/home', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'subscription-key': subscriptionKey
},
body: JSON.stringify(data)
})
return rawResponse.json();
}