Address Validation 3 C# Rest Code Snippet

string mainURL = "https://trial.serviceobjects.com/AV3/api.svc/GetBestMatchesJson/" + businessName + "/" + address + "/" + address2 + "/" + city + "/" + state + "/" + zip + "/" + licenseKey;
 
AV3Response result = null;
  
HttpWebRequest request = WebRequest.Create(mainURL ) as HttpWebRequest;
request.Timeout = 5000;//timeout for get operation
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
    if (response.StatusCode != HttpStatusCode.OK)
        throw new Exception(String.Format(
        "Server error (HTTP {0}: {1}).",
        response.StatusCode,
        response.StatusDescription));
    //parse response
    DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(AV3Response));
    object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
    result = objResponse as AV3Response;
//processing result
if (result.error == null)
{
    //process result
}
else
{
    //process error
}
Address Validation 3 Java Rest Code Snippet
BestMatchesResponse.Error error = null;
BestMatchesResponse.Address[] addresses = null;
AV3RestClient AV3Client = new AV3RestClient();
BestMatchesResponse result = AV3Client.GetBestMatches(business, addr, addr2, city, state, postalCode, licenseKey);
if (result != null) {
error = result.error;
addresses = result.Addresses;
}
  
//Process Results
if (error == null) {
    //DOTS Address Validation Results
         
}
  
//Process Errors
else{
}
    //DOTS Address Validation Error
     
}

Address Validation 3 PHP Rest Code Snippets

$URL="https://trial.serviceobjects.com/av3/api.svc/GetBestMatchesJson/".rawurlencode($Business)."/".rawurlencode($Address)."/".rawurlencode($Address2)."/".rawurlencode($City)."/".rawurlencode($State)."/".rawurlencode($PostalCode)."/".rawurlencode($LicenseKey);
         
// Get cURL resource
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Address Validation 3'));
curl_setopt($curl, CURLOPT_TIMEOUT, 5); //timeout in seconds
// Send the request & save response to $resp
$resp = curl_exec($curl);
$jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($decoded), RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val)
{
    if(is_array($val))
    {
        echo "Address Validation 3 Results";
    } 
    else
    {
        echo "$key";
        echo "$val";
    }
}

Address Validation 3 RoR Rest Code Snippets

    #This sets the default timeout for HTTParty get operation. This must be set in order to use the gem
    default_timeout = 10
 
     
    businessname = @request.businessname
    address1 = @request.address1
    address2 = @request.address2
    city = @request.city
    state = @request.state
    postalcode = @request.postalcode
    licensekey = @request.licensekey
     
           
     
    #Set Primary and Backup URLs as needed. This method encodes and standardizes the URI to pass to the REST service.
    primaryURL = URI.encode("https://trial.serviceobjects.com/AV3/api.svc/GetBestMatchesJson?BusinessName=" + businessname + "&Address=" + address1 + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey)
    backupURL = URI.encode("https://trial.serviceobjects.com/AV3/api.svc/GetBestMatchesJson?BusinessName=" + businessname + "&Address=" + address1 + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey)
     
     
    #These are set to access the hash that is returned
    @av3addresses ="Addresses"
    @av3error = "Error"
 
      #Begins the call the RESTful web service
    begin
      response = HTTParty.get(primaryURL, timeout: default_timeout)
 
      #processes the response to display to the screen
      #Passes the response returned from HTTParty and processes them depending on the results
      processresults(response)
       
     rescue StandardError => e
          begin
          #uses the backupURl in the event that the service encountered an error
          response = HTTParty.get(backupURL, timeout: default_timeout)
         
        #processes the response returned from using the backupURL
          processresults(response)
 
        #If the backup url railed this will raise an error and display the
        #error message returned from the HTTParty gem.
          rescue StandardError => error
              @status = error.message
              @displaydata = {"Error" => "An Error Occured"}
          end
    end
     
end
  private     
  def processresults(response)   
          #Processes Error Response from the web service 
          #Processes a valid response from the web service
           
  end
  

Address Validation US 3 Python Code Snippet

mBusinessName = BusinessName.get()
if mBusinessName is None or mBusinessName == "":
    mBusinessName = " "
mAddress = Address.get()
if mAddress is None or mAddress == "":
    mAddress = " "
mAddress2 = Address2.get()
if mAddress2 is None or mAddress2 == "":
    mAddress2 = " "
mCity = City.get()
if mCity is None or mCity == "":
    mCity = " "
mState = State.get()
if mState is None or mState == "":
    mState = " "
mPostalCode = PostalCode.get()
if mPostalCode is None or mPostalCode == "":
    mPostalCode = " "
mLicenseKey = LicenseKey.get()
if mLicenseKey is None or mLicenseKey == "":
    mLicenseKey = " "
 
#Set the primary and backup URLs as necessary
primaryURL = 'https://trial.serviceobjects.com/AV3/api.svc/GetBestMatchesJson?'
backupURL = 'https://trial.serviceobjects.com/AV3/api.svc/GetBestMatchesJson?'
#The Requests package allows the user to format the path parameters like so instead of having to manually insert them into the URL
inputs = {'BusinessName': mBusinessName, 'Address': mAddress, 'Address2': mAddress2, 'City':mCity, 'State':mState, 'PostalCode': mPostalCode, 'LicenseKey': mLicenseKey}
try:
    result = requests.get(primaryURL, params=inputs)
    #Outputs the results as json
    outputs = result.json()
     #Handel response and check for errors
     
#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()
        #Handel response and check for errors
         
    #Displays an Error if the backup and primary URL failed
    except:
        Label(swin.window, text='Error').pack()
        print (result)

Address Validation 3 ColdFusion Rest Snippet

<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq "" >
    <cftry>
        <cfset primaryURL = "https://trial.serviceobjects.com/AV3/api.svc/GetBestMatches?BusinessName=#BusinessName#&Address=#Address#&Address2=#Address2#&City=#City#&State=#State#&PostalCode=#PostalCode#&LicenseKey=#LicenseKey#">
        <cfhttp url="#primaryURL#"
        method="get"
        result="response">
        <cfset outputs = XmlParse(response.FileContent)>
        <cfcatch>
            <cftry>
                <cfset backupURL = "https://trial.serviceobjects.com/AV3/api.svc/GetBestMatches?BusinessName=#BusinessName#&Address=#Address#&Address2=#Address2#&City=#City#&State=#State#&PostalCode=#PostalCode#&LicenseKey=#LicenseKey#">
                <cfhttp url="#backupURL#"
                method="get"
                result="response">
                <cfset outputs = XmlParse(response.FileContent)>             
                <cfcatch >
                    <cfoutput >
                        The Following Error Occured: #response.StatusCode#
                    </cfoutput>
                </cfcatch>
            </cftry>
        </cfcatch>
    </cftry>
</cfif>

Address Validation 3 VB Rest Code Snippet

Try
    'encodes the URLs for the get Call. Set the primary and back urls as necessary
    Dim primaryurl As String = "https://trial.serviceobjects.com/AV3/api.svc/GetBestMatches?BusinessName=" + businessname + "&Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey
    Dim backupurl As String = "https://trial.serviceobjects.com/AV3/api.svc/GetBestMatches?BusinessName=" + businessname + "&Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey
    Dim wsresponse As AV3Response.BestMatchesResponse = httpGet(primaryurl)
 
    'checks if a response was returned from the service, uses the backup url if response is null or a fatal error occured.
    If wsresponse Is Nothing OrElse (wsresponse.[Error] IsNot Nothing AndAlso wsresponse.[Error].TypeCode = "3") Then
        wsresponse = httpGet(backupurl)
    End If
    If wsresponse.[Error] IsNot Nothing Then
        ProcessErrorResponse(wsresponse.[Error])
    Else
        ProcessSuccessfulResponse(wsresponse)
 
    End If
Catch ex As Exception
    'Displays the relevant error mesasge if both backup and primary urls failed.
    StatusLabel.Text = ex.Message
    StatusLabel.Visible = True
End Try

Address Validation 3 TSQL Rest Code Snippet

BEGIN
    SET @sUrl = 'https://trial.serviceobjects.com/av3/api.svc/GetBestMatches?BusinessName=' + @businessname + '&Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&PostalCode=' + @postalcode + '&LicenseKey=' + @key
    EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
    EXEC sp_OAMethod @obj, 'Open', NULL, 'Get', @sUrl, false
    EXEC sp_OAMethod @obj, 'send'
    EXEC sp_OAGetProperty @obj, 'responseText', @response OUT
             
    --Checks the Response for a fatal error or if null.
    IF @response IS NULL
    BEGIN
        SET @sBackupUrl = 'https://trial.serviceobjects.com/av3/api.svc/GetBestMatches?BusinessName=' + @businessname + '&Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&PostalCode=' + @postalcode + '&LicenseKey=' + @key
        EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
        EXEC sp_OAMethod @obj, 'Open', NULL, 'Get', @sBackupUrl, false
        EXEC sp_OAMethod @obj, 'send'
        EXEC sp_OAGetProperty @obj, 'responseText', @response OUT
    END
END

Address Validation 3 NodeJS REST Code Snippet

 //Set backup and primary URL as necessary
var primaryUrl = 'https://trial.serviceobjects.com/av3/api.svc/GetBestMatches?BusinessName=' + BusinessName + '&Address='+Address+'&Address2='+ Address2 + '&City=' + City +'&State=' + State +'&PostalCode=' + PostalCode +'&LicenseKey=' + LicenseKey;
var backupUrl = 'https://trial.serviceobjects.com/av3/api.svc/GetBestMatches?BusinessName=' + BusinessName + '&Address='+Address+'&Address2='+ Address2 + '&City=' + City +'&State=' + State +'&PostalCode=' + PostalCode +'&LicenseKey=' + LicenseKey;
 
var req = http.get(primaryUrl, function(res) {
    res.setEncoding('utf8');
    res.on('data', function (results) {
        var parser = require('xml2js').Parser({explicitArray: false});
        parser.parseString(results, function (err, outputs) {
            if (outputs.BestMatchesResponse.Error !=  null)
            {
                //Indicates a Fatal error has occured. If this happens, the logic will then failover to the backup url
                if (outputs.BestMatchesResponse.Error.TypeCode == "3")
                {
                    var backupReq = http.get(backupUrl, function(backupRes) {
                        backupRes.setEncoding('utf8');
                        backupRes.on('data', function (results) {
                                var parser = require('xml2js').Parser({explicitArray: false});
                                parser.parseString(results, function (err, outputs) {
                                    console.log("Backup Call Was Used.");
                                    response.end(JSON.stringify(outputs , null, 3));
                                });
                            });
                        });
                }
                else
                {
                    //Will Display the JSON Formatted Error Response here
                    response.end(JSON.stringify(outputs, null, 3));
                    return;
                }
            }
            else
            {
                //Will Display the JSON Formatted Valid Response here
                response.end(JSON.stringify(outputs, null, 3));
                return;
            }
        });
    });
});