C#
C# 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.
C# Example
using System.Text;
using System.Text.Json;
const string baseUrl = "<insertenvironmenturl>";
const string subscriptionKey = "<yourapikeyhere>";
await CallAutoQuotingApis();
await CallHomeQuotingApis();
Console.ReadLine();
async Task CallHomeQuotingApis()
{
var ioaApi = new QuotingApi(baseUrl, subscriptionKey);
var result = await ioaApi.GenerateHomeQuote(new ()
{
FirstName = "Jeff",
LastName = "Ward",
CampaignCode = "MAGIC",
Email = "Test@test.com",
Phone = "541 754 3010",
DateOfBirth = "1990-05-29",
ProductData = new()
{
Address = new()
{
AddressLine1 = "Appleton Avenue",
AddressLine2 = "Appleton Area",
ApartmentNumber = "6b",
City = "Orlando",
County = "Orange County",
State = "FL",
StreetNumber = "1434",
Zip = "32806"
},
PropertyDetails = new()
{
SquareFootage = "3050",
YearBuilt = "2018",
PropertyType = "SingleFamily",
ResidenceUsage = "PrimaryResidence",
RoofMaterial = "StandardShingle",
Bedrooms = "2",
Bathrooms = "2",
MarketValue = "125000",
FireAlarm = "Local",
BurglarAlarm = "CentrallyMonitored",
GatedCommunity = false
},
Gender = "Male",
PropertyPurchasedInLastSixMonths = true,
PreviousAddress = new()
{
StreetNumber = "1",
AddressLine1 = "Appleton Avenue",
AddressLine2 = "Appleton Area",
ApartmentNumber = "2a",
City = "Orlando",
County = "Orange County",
State = "FL",
Zip = "32806"
},
Carrier = "Progressive",
CoverageYears = "5",
Rating = "Good"
},
Metadata = new()
{
["TestKey1"] = "TestValue1",
["TestKey2"] = "TestValue2"
}
});
Console.WriteLine(result.Payload.QuotesCorrelationId);
const int maxRetryCount = 10;
int currentRetryCount = 0;
QuotesResponse quotes = null;
while (currentRetryCount <= maxRetryCount)
{
await Task.Delay(3000);
Console.WriteLine($"Polling for quotes {currentRetryCount + 1}");
quotes = await ioaApi.RetrieveQuote(result.Payload.QuotesCorrelationId, subscriptionKey);
currentRetryCount++;
}
Console.WriteLine(quotes.Payload.Quotes.Count());
if (quotes.Payload.Quotes.Count() > 0)
{
foreach (var quote in quotes.Payload.Quotes)
{
Console.WriteLine($"{quote.CarrierName} - {quote.PremiumDetails.MonthlyPremiumEstimate} for {quote.PremiumDetails.TermInMonths} months");
}
}
}
async Task CallAutoQuotingApis()
{
var ioaApi = new QuotingApi(baseUrl, subscriptionKey);
var result = await ioaApi.GenerateAutoQuote(new()
{
FirstName = "Jeff",
LastName = "Ward",
CampaignCode = "MAGIC",
Email = "Test@test.com",
Phone = "541 754 3010",
DateOfBirth = "1990-05-29",
ProductData = new()
{
Address = new()
{
AddressLine1 = "Appleton Avenue",
AddressLine2 = "Appleton Area",
ApartmentNumber = "6b",
City = "Orlando",
County = "Orange County",
State = "FL",
StreetNumber = "1434",
Zip = "32806"
},
Gender = "Male",
MaritalStatus = "Married",
YearsAtCurrentAddress = "10",
HomeOwnership = "OwnedHouse",
CreditRating = "Excellent",
Bankruptcy = false,
CurrentCarrier = "Progressive",
CurrentInsuranceExpirationDate = "2023-05-09",
CurrentInsuranceYears = "TenOrMoreYears",
BodilyInjuryLiabilityLimit = "BI_100000_300000",
Vehicles = new()
{
new()
{
Vin = "19XFC1F84HE004530",
Year = "2023",
Make = "Honda",
Model = "Civic",
SubModel = "Type R",
PrimaryUse = "Personal",
GarageType = "AttachedGarage",
ParkedAtMailingAddress = true,
GaragingAddress = new()
{
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"
}
},
Drivers = new()
{
new()
{
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 = new()
{
new()
{
ViolationDate = "2020-01-01",
Type = "CellPhone"
}
},
Claims = new()
{
new()
{
ClaimDate = "2022-06-01",
Amount = "450",
Type = "Wing mirror"
}
}
}
}
},
Metadata = new()
{
["TestKey1"] = "TestValue1",
["TestKey2"] = "TestValue2"
}
});
Console.WriteLine(result.Payload.QuotesCorrelationId);
const int maxRetryCount = 10;
int currentRetryCount = 0;
QuotesResponse quotes = null;
while (currentRetryCount <= maxRetryCount)
{
await Task.Delay(3000);
Console.WriteLine($"Polling for quotes {currentRetryCount + 1}");
quotes = await ioaApi.RetrieveQuote(result.Payload.QuotesCorrelationId, subscriptionKey);
currentRetryCount++;
}
Console.WriteLine(quotes.Payload.Quotes.Count());
if (quotes.Payload.Quotes.Count() > 0)
{
foreach (var quote in quotes.Payload.Quotes)
{
Console.WriteLine($"{quote.CarrierName} - {quote.PremiumDetails.MonthlyPremiumEstimate} for {quote.PremiumDetails.TermInMonths} months");
}
}
}
public class QuotingApi
{
private readonly HttpClient httpClient;
private readonly JsonSerializerOptions options;
public QuotingApi(string baseUri, string subscriptionKey)
{
this.httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(baseUri);
httpClient.DefaultRequestHeaders.Add("subscription-key", subscriptionKey);
options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };
}
public async Task<QuotesRequestResponse> GenerateHomeQuote(HomeQuotesRequest request)
{
var response = await httpClient.PostAsync("/quoting/v3/quotes/home/request",
new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"));
return response.IsSuccessStatusCode
? JsonSerializer.Deserialize<QuotesRequestResponse>(await response.Content.ReadAsStringAsync(),
options)
: null;
}
public async Task<QuotesRequestResponse> GenerateAutoQuote(AutoQuotesRequest request)
{
var response = await httpClient.PostAsync("/quoting/v3/quotes/auto/request",
new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"));
return response.IsSuccessStatusCode
? JsonSerializer.Deserialize<QuotesRequestResponse>(await response.Content.ReadAsStringAsync(),
options)
: null;
}
public async Task<QuotesResponse> RetrieveQuote(Guid quoteCorrelationId, string subscriptionKey)
{
var response = await httpClient.GetAsync("/quoting/v3/quotes/" + quoteCorrelationId);
return response.IsSuccessStatusCode
? JsonSerializer.Deserialize<QuotesResponse>(await response.Content.ReadAsStringAsync(),
options)
: null;
}
}