Address Validation US 4 C# Rest Code Snippet

string parameters = $"Mode={HttpUtility.UrlEncode(mode)}&Address1={HttpUtility.UrlEncode(address1)}"+
"&Address2={HttpUtility.UrlEncode(address2)}&City={HttpUtility.UrlEncode(city)}"+
"&State={HttpUtility.UrlEncode(state)}&Zip={HttpUtility.UrlEncode(zip)}"+
"&BusinessName={HttpUtility.UrlEncode(businessName)}&FirstName={HttpUtility.UrlEncode(firstName)}"+
"&MiddleName={HttpUtility.UrlEncode(middleName)}&LastName={HttpUtility.UrlEncode(lastName)}"+
"&PhoneNumber={HttpUtility.UrlEncode(phoneNumber)}&Options={HttpUtility.UrlEncode(options)}"+
"&AuthID={AV4_KEY}";
HttpResponseMessage resp = Utils.HttpGet($"https://strial.serviceobjects.com/AV4/ValidateAddress?{parameters}");

HttpContent content = resp.Content;
string result = content.ReadAsStringAsync().Result;
AV4Response AV4Resp = new AV4Response();
if (resp.StatusCode == HttpStatusCode.OK)
{

    AV4Resp.AV4Resp = JsonConvert.DeserializeObject<AV4.ValidateAddressResponse>(result);
	if (AV4Resp.AV4Resp != null)
    {
        try
        {
            string status = AV4Resp.AV4Resp.Status;
        }
        catch (Exception ex)
        {
        }
        try
        {
            string statusDetails = AV4Resp.AV4Resp.statusDetails;
        }
        catch (Exception ex)
        {
        }
        List<AV4.AddressInfo> AI = AV4Resp.AV4Resp.Addresses.ToList();
        List<AV4.AddressInfo> Validations = AI.Where(x => x.Source != "InputParsed").ToList();
        AV4.AddressInfo ParsedAddress = AV4Resp.AV4Resp.ParsedInput;
        if (Validations.Count > 0)
        {
            try
            {
                string rating = Validations[0].Rating == null ? "" : Validations[0].Rating.ToString();
            }
            catch (Exception ex)
            {
            }

            try
            {
                string validationType = Validations[0].ValidationType == null ? "" : Validations[0].ValidationType;
            }
            catch (Exception ex)
            {
            }

            try
            {
                string address1 = Validations[0].Address == null ? "" : Validations[0].Address;
            }
            catch (Exception ex)
            {
            }
			.
			.
			.
			.
			.
			.
		}
		.
		.
		.
		.
	}
}
else
{
    AV4Resp.AV4ProblemDetails = JsonConvert.DeserializeObject<AV4.ProblemDetails>(result);
}





public static HttpResponseMessage HttpGet(string requestUrl)
{
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
    HttpClient client = new HttpClient();
    var task = Task.Run(() => client.GetAsync(requestUrl));
    task.Wait();
    HttpResponseMessage response = task.Result;
    return response;
}

Address Validation US 4 Python Code Snippet

#The Requests package allows the user to format the path parameters like so instead of having to manually insert them into the URL

#These endpoints are to the trial environment.  In production, please use sws and swsbackup for primaryURL and backupURL. For example, primaryURL = 'https://sws.serviceobjects.com/AV4/ValidateAddress?'

primaryURL = 'https://strial.serviceobjects.com/AV4/ValidateAddress?'
backupURL = 'https://strial.serviceobjects.com/AV4/ValidateAddress?'

inputs = {'Mode': Mode, 'Address1': Address1, 'Address2': Address2, 'City': City, 'State': State, 'ZIP': ZIP,
'BusinessName': BusinessName, 'FirstName': FirstName, 'MiddleName': MiddleName,'LastName': LastName, 'PhoneNumber': PhoneNumber, 
'Options': Options,'AuthID': AuthID}

        try:
            result = requests.get(primaryURL, params=inputs)
            #Outputs the results as json
            outputs = result.json()
            #checks the output for Errors and displays the info accordingly
            if 'Error' in outputs.keys():
                try:
                    result = requests.get(backupURL, params=inputs)
                    #Outputs the results as json
                    outputs = result.json()
                    #checks the output for Errors and displays the info accordingly
                    if 'Error' in outputs.keys():
                        raise
                    else:
                        return outputs
            #Displays an Error if the backup and primary URL failed
                except e:
                    raise
            else:
                return outputs

        #Uses the backup URL call the webservice if the primary URL failed
        except:
            try:
                result = requests.get(backupURL, params=inputs)
                #Outputs the results as json
                outputs = result.json()
                #checks the output for Errors and displays the info accordingly
                if 'Error' in outputs.keys():
                    raise
                else:
                    return outputs
            #Displays an Error if the backup and primary URL failed
            except e:
                raise
        return