Address Geocode – US C# Code Snippet

string primaryURL = "https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=" + address + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey;
string backupURL = "https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=" + address + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey;
Location_V4 response = httpGet(primaryURL);
if (response == null || (response.Error != null && response.Error.Number == "4"))
{
    response = httpGet(backupURL);
}
if (response.Error == null)
{
    ProcessValidResponse(response);
}
else
{
    ProcessErrorResponse(response.Error);
}

Address Geocode – US Java Code Snippet

JSONObject results = RestClient(mainURL);  
try {
    if (ErrorMessages != null || (results.getJSONObject("Location_V4").has("Error") && results.getJSONObject("Location_V4").getJSONObject("Error").get("Number") == "3")) {
        // BACKUP
        results = RestClient(backupURL);
    }
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
  
return results;

Address Geocode – US PHP Code Snippet

$URL = "https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=".urlencode($Address)."&City=".urlencode($City)."&State=".urldecode($State)."&PostalCode=".urldecode($PostalCode)."&LicenseKey=".urlencode($LicenseKey);
//use backup url once given purchased license key
$backupURL = "https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=".urlencode($Address)."&City=".urlencode($City)."&State=".urldecode($State)."&PostalCode=".urldecode($PostalCode)."&LicenseKey=".urlencode($LicenseKey);
try{
    // Get cURL resource
    $curl = curl_init();
    curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Geocode US'));
    curl_setopt($curl, CURLOPT_TIMEOUT, 50); //timeout in seconds
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
                curl_close($curl);
    $outputs = new SimpleXMLElement($resp);
    // Close request to clear up some resources
    if($outputs == null || ($outputs->Error != null || $outputs->Error->Number == "4"))
    {
                        $curl = curl_init();
        echo "IN back up block";
        curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $backupURL, CURLOPT_USERAGENT => 'Service Objects Geocode US'));
        curl_setopt($curl, CURLOPT_TIMEOUT, 50); //timeout in seconds
        // Send the request & save response to $resp
        $resp = curl_exec($curl);
        if($resp == false)
        {
            curl_close($curl);
            return;
        }
                        curl_close($curl);
                        $outputs = new SimpleXMLElement($resp);
                          
    }

Address Geocode – US RoR Code Snippet

#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/GCR/api.svc/xml/GetBestMatch_V4?Address=" + address + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey)
backupURL = URI.encode("https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=" + address + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey)
#These are set to access the hash that is returned
@gcrresult ="Location_V4"
@gcrerror = "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" => "A Big Error Occured"}
        end
end

Address Geocode – US Python Code Snippet

#Set the primary and backup URLs as necessary
primaryURL = 'https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?'
backupURL = 'https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?'
#The
 Requests package allows the user to format the path parameters like so
instead of having to manually insert them into the URL
inputs = {'Address': mAddress, 'City': mCity, 'State': mState, 'PostalCode': mPostalCode, 'LicenseKey': mLicenseKey}
try:
    result = requests.get(primaryURL, params=inputs)
    #Parses the XML response from the service into a python dictionary type
    outputs = xmltodict.parse(result.content)
    #checks the output for Errors and displays the info accordingly
    if 'Error' in outputs['Location_V4']:
        #loops through the response from the service and prints the values to the screen.
        for key, value in outputs['Location_V4']['Error'].iteritems():
            Label(swin.window, text=str(key) + " : " + str(value)).pack()
    else:
        #Removes unnecessary entries that were parsed into the python dictionary from XML response of service
        outputs['Location_V4'].pop("@xmlns:i", None)
        outputs['Location_V4'].pop("@xmlns:xsd", None)
        outputs['Location_V4'].pop("@xmlns", None)
        for key, value in outputs['Location_V4'].iteritems():
            if key!= 'InformationComponents':
                Label(swin.window, text=str(key) + " : " + str(value)).pack()
        if 'InformationComponents' in outputs['Location_V4']:
            infoComponent = outputs['Location_V4']['InformationComponents']['InformationComponent']
            for i in range(0, len(infoComponent)):
                Label(swin.window, text=str(infoComponent[i]["Name"]) + ": " + str(infoComponent[i]["Value"])).pack()

Address Geocode – US ColdFusion Code Snippet

<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq "" >
    <cftry>
        <cfset primaryURL = "https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=#Address#&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/GCR/api.svc/xml/GetBestMatch_V4?Address=#Address#&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 Geocode – US VB Code Snippet

'encodes the URLs for the get Call. Set the primary and back urls as necessary
Dim primaryurl As String = "https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=" + address + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey
Dim backupurl As String = "https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=" + address + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "&LicenseKey=" + licensekey
Dim wsresponse As GCRResponse.Location_V4 = 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].Number = "4") Then
    wsresponse = httpGet(backupurl)
End If
If wsresponse.[Error] IsNot Nothing Then
    ProcessErrorResponse(wsresponse.[Error])
Else
    ProcessSuccessfulResponse(wsresponse)

Address Geocode – US TSQL Code Snippet

--If a production key is purchased, this will execute the failover
IF @isLiveKey = 1
BEGIN
    SET @sUrl = 'https://trial.serviceobjects.com/GCR/api.svc/xml/GetBestMatch_V4?Address=' + @address + '&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/GCR/api.svc/xml/GetBestMatch_V4?Address=' + @address + '&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 GeoCoder NodeJS Code Snippet

var primaryUrl = 'https://trial.serviceobjects.com/gcr/api.svc/XML/GetBestMatch_V4?Address='+Address+ '&City=' + City +'&State=' + State +'&PostalCode=' + PostalCode +'&LicenseKey=' + LicenseKey;
var backupUrl = 'https://trial.serviceobjects.com/gcr/api.svc/XML/GetBestMatch_V4?Address='+Address+ '&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,ignoreAttrs: true});
    parser.parseString(results, function (err, outputs) {
        if (outputs.Location_V4.Error !=  null)
        {
            //Indicates a Fatal error has occured. If this happens, the logic will then failover to the backup url
            if (outputs.Location_V4.Error.Number == "4")
            {
                var backupReq = http.get(backupUrl, function(backupRes) {
                    backupRes.setEncoding('utf8');
                    backupRes.on('data', function (results) {
                            var parser = require('xml2js').Parser({explicitArray: false,ignoreAttrs: true});
                            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;
        }
    });