C#
C# Example
The following example calls the consumer journey Auto and Home Insurance APIs (The data transfer object types used for the request and response are omitted for brevity)
C# Example
using System.Text;
using System.Text.Json;
const string baseUrl = "<insert-environment-url>";
var subscriptionKey = "<your-subscription-key-here>";
var ioaApi = new ConsumerJourneyApi(baseUrl, subscriptionKey);
var homeResponse = await ioaApi.GenerateConsumerHomeJourney(new()
{
FirstName = "Jeff",
LastName = "Ward",
CampaignCode = "MAGIC",
Email = "Test@test.com",
DateOfBirth = "1990-05-29",
Phone = "541 754 3010",
ProductData = new()
{
Address = new()
{
StreetNumber = "1434",
AddressLine1 = "Appleton Avenue",
AddressLine2 = "",
ApartmentNumber = "6b",
City = "Orlando",
County = "Orange County",
State = "FL",
Zip = "32806"
},
MortgageeLender = new()
{
CompanyName = "Mortgage Company",
AddressLine1 = "1025 Appleton Avenue",
AddressLine2 = "Business District",
City = "Orlando",
State = "FL",
Zip = "32806",
LoanNumber = "M123456"
},
PropertyPurchasedInLastSixMonths = true,
PreviousAddress = new()
{
StreetNumber = "1200",
AddressLine1 = "Appleton Avenue",
AddressLine2 = "Appleton Area",
ApartmentNumber = "",
City = "Orlando",
County = "Orange County",
State = "FL",
Zip = "32806"
},
Gender = "Male",
PropertyDetails = new()
{
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 = new()
{
["TestKey1"] = "TestValue1",
["TestKey2"] = "TestValue2"
}
});
Console.WriteLine(homeResponse.Payload.OnlineJourneyUrl);
var autoresponse = await ioaApi.GenerateConsumerAutoJourney(new()
{
FirstName = "Jake",
LastName = "Ward",
DateOfBirth = "1990-05-29",
Email = "test@test.com",
Phone = "541 754 3010",
CampaignCode = "MAGIC",
ProductData = new()
{
Address = new()
{
StreetNumber = "1434",
AddressLine1 = "Appleton Avenue",
AddressLine2 = "",
ApartmentNumber = "6b",
City = "Orlando",
County = "Orange County",
State = "FL",
Zip = "32806"
},
Gender = "Male",
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"
}
}
}
},
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"
}
},
MaritalStatus = "Married",
YearsAtCurrentAddress = "10",
HomeOwnership = "OwnedHouse",
CreditRating = "Excellent",
Bankruptcy = false,
CurrentCarrier = "Progressive",
CurrentInsuranceExpirationDate = "2023-05-09",
CurrentInsuranceYears = "TenOrMoreYears",
BodilyInjuryLiabilityLimit = "BI_100000_300000"
},
Metadata = new()
{
["TestKey1"] = "TestValue1",
["TestKey2"] = "TestValue2"
}
});
Console.WriteLine(autoresponse.Payload.OnlineJourneyUrl);
Console.ReadLine();
public class ConsumerJourneyApi
{
private readonly HttpClient httpClient;
private readonly JsonSerializerOptions options;
public ConsumerJourneyApi(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<ConsumerResponse> GenerateConsumerHomeJourney(ConsumerHomeRequest request)
{
var response = await httpClient.PostAsync("/consumer-journey/v3/consumer-data/home",
new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"));
return response.IsSuccessStatusCode
? JsonSerializer.Deserialize<ConsumerResponse>(await response.Content.ReadAsStringAsync(),
options)
: null;
}
public async Task<ConsumerResponse> GenerateConsumerAutoJourney(ConsumerAutoRequest request)
{
var response = await httpClient.PostAsync("/consumer-journey/v3/consumer-data/auto",
new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"));
return response.IsSuccessStatusCode
? JsonSerializer.Deserialize<ConsumerResponse>(await response.Content.ReadAsStringAsync(),
options)
: null;
}
}