- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- TSQL
FastTax C# Rest Code Snippet
BestMatchResponse result = null;
string mainURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey;
// A trial license key is not compatible with the backup datacenter.
// The backup url is provided with a production license key.
string backupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey;
try
{
result = HttpGet(mainURL);
//NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP
if (result == null|| (result.Error != null && result.Error.Number == "3"))
{
return HttpGet(backupURL);
}
else
{
return result;
}
}
catch (Exception)
{
//ERROR IN MAIN URL - USING BACKUP
return HttpGet(backupURL);
}
BestMatchResponse result = null;
string mainURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey;
// A trial license key is not compatible with the backup datacenter.
// The backup url is provided with a production license key.
string backupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey;
try
{
result = HttpGet(mainURL);
//NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP
if (result == null|| (result.Error != null && result.Error.Number == "3"))
{
return HttpGet(backupURL);
}
else
{
return result;
}
}
catch (Exception)
{
//ERROR IN MAIN URL - USING BACKUP
return HttpGet(backupURL);
}
BestMatchResponse result = null; string mainURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey; // A trial license key is not compatible with the backup datacenter. // The backup url is provided with a production license key. string backupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey; try { result = HttpGet(mainURL); //NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP if (result == null|| (result.Error != null && result.Error.Number == "3")) { return HttpGet(backupURL); } else { return result; } } catch (Exception) { //ERROR IN MAIN URL - USING BACKUP return HttpGet(backupURL); }
FastTax Java Rest Code Snippet
if ((Address == null)||(Address == ""))
Address = " ";
if ((Address2 == null)||(Address2 == ""))
Address2 = " ";
if ((City == null)||(City == ""))
City = " ";
if ((State == null)||(State == ""))
State = " ";
if ((Zip == null)||(Zip == ""))
Zip = " ";
if ((TaxType == null)||(TaxType == ""))
TaxType = " ";
if ((LicenseKey == null)||(LicenseKey == ""))
LicenseKey = "YOUR-LICENSE-KEY";
try {
Address = URLEncoder.encode(Address,"UTF-8").replaceAll("+", "%20");
Address2 = URLEncoder.encode(Address2,"UTF-8").replaceAll("+", "%20");
City = URLEncoder.encode(City,"UTF-8").replaceAll("+", "%20");
State = URLEncoder.encode(State,"UTF-8").replaceAll("+", "%20");
Zip = URLEncoder.encode(Zip,"UTF-8").replaceAll("+", "%20");
TaxType = URLEncoder.encode(TaxType,"UTF-8").replaceAll("+", "%20");
LicenseKey = URLEncoder.encode(LicenseKey,"UTF-8").replaceAll("+", "%20");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BestMatchResponse Response = null;
String Request = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey;
try {
Response = DoHttpRequest(Request);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if ((Address == null)||(Address == ""))
Address = " ";
if ((Address2 == null)||(Address2 == ""))
Address2 = " ";
if ((City == null)||(City == ""))
City = " ";
if ((State == null)||(State == ""))
State = " ";
if ((Zip == null)||(Zip == ""))
Zip = " ";
if ((TaxType == null)||(TaxType == ""))
TaxType = " ";
if ((LicenseKey == null)||(LicenseKey == ""))
LicenseKey = "YOUR-LICENSE-KEY";
try {
Address = URLEncoder.encode(Address,"UTF-8").replaceAll("+", "%20");
Address2 = URLEncoder.encode(Address2,"UTF-8").replaceAll("+", "%20");
City = URLEncoder.encode(City,"UTF-8").replaceAll("+", "%20");
State = URLEncoder.encode(State,"UTF-8").replaceAll("+", "%20");
Zip = URLEncoder.encode(Zip,"UTF-8").replaceAll("+", "%20");
TaxType = URLEncoder.encode(TaxType,"UTF-8").replaceAll("+", "%20");
LicenseKey = URLEncoder.encode(LicenseKey,"UTF-8").replaceAll("+", "%20");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BestMatchResponse Response = null;
String Request = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey;
try {
Response = DoHttpRequest(Request);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if ((Address == null)||(Address == "")) Address = " "; if ((Address2 == null)||(Address2 == "")) Address2 = " "; if ((City == null)||(City == "")) City = " "; if ((State == null)||(State == "")) State = " "; if ((Zip == null)||(Zip == "")) Zip = " "; if ((TaxType == null)||(TaxType == "")) TaxType = " "; if ((LicenseKey == null)||(LicenseKey == "")) LicenseKey = "YOUR-LICENSE-KEY"; try { Address = URLEncoder.encode(Address,"UTF-8").replaceAll("+", "%20"); Address2 = URLEncoder.encode(Address2,"UTF-8").replaceAll("+", "%20"); City = URLEncoder.encode(City,"UTF-8").replaceAll("+", "%20"); State = URLEncoder.encode(State,"UTF-8").replaceAll("+", "%20"); Zip = URLEncoder.encode(Zip,"UTF-8").replaceAll("+", "%20"); TaxType = URLEncoder.encode(TaxType,"UTF-8").replaceAll("+", "%20"); LicenseKey = URLEncoder.encode(LicenseKey,"UTF-8").replaceAll("+", "%20"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BestMatchResponse Response = null; String Request = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + Address + "&Address2=" + Address2 + "&City=" + City + "&State=" + State + "&Zip=" + Zip + "&TaxType=" + TaxType + "&LicenseKey=" + LicenseKey; try { Response = DoHttpRequest(Request); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
FastTax PHP Rest Code Snippet
$TrialURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=".rawurlencode($Address)."&Address2=".rawurlencode($Address2)."&City=".rawurlencode($City)."&State=".rawurlencode($State)."&Zip=".rawurlencode($Zip)."&TaxType=".rawurlencode($TaxType)."&LicenseKey=".rawurlencode($LicenseKey);
// A trial license key is not compatible with the backup datacenter.
// The backup url is provided with a production license key.
$BackupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=".rawurlencode($Address)."&Address2=".rawurlencode($Address2)."&City=".rawurlencode($City)."&State=".rawurlencode($State)."&Zip=".rawurlencode($Zip)."&TaxType=".rawurlencode($TaxType)."&LicenseKey=".rawurlencode($LicenseKey);
// Get cURL resource
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $TrialURL, CURLOPT_USERAGENT => 'Service Objects Fast Tax'));
//Https peer certification validation turned off
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT); //timeout in milliseconds
// Send the request & save response to $resp
$resp = curl_exec($curl);
$status = curl_getinfo($curl);
$decoded = json_decode($resp, TRUE);
if($resp == FALSE || (isset ($decoded['Error']) != NULL && $decoded['Error']['Number'] == 4) || (isset($status) && $status['http_code'] != 200))
{
// the first service has failed over
// create a new request to the backURL
$curl2 = curl_init();
curl_setopt_array($curl2, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $BackupURL, CURLOPT_USERAGENT => 'Service Objects Fast Tax'));
//Https peer certification validation turned off
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl2, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT); //timeout in milliseconds
// Send the request & save response to $resp
$resp = curl_exec($curl2);
$decoded = json_decode($resp, TRUE);
if($resp == false)
{
echo "<b> Both rest calls failed </b>";
curl_close($curl2);
return;
}
}
//Close request to clear up some resources
curl_close($curl);
$TrialURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=".rawurlencode($Address)."&Address2=".rawurlencode($Address2)."&City=".rawurlencode($City)."&State=".rawurlencode($State)."&Zip=".rawurlencode($Zip)."&TaxType=".rawurlencode($TaxType)."&LicenseKey=".rawurlencode($LicenseKey);
// A trial license key is not compatible with the backup datacenter.
// The backup url is provided with a production license key.
$BackupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=".rawurlencode($Address)."&Address2=".rawurlencode($Address2)."&City=".rawurlencode($City)."&State=".rawurlencode($State)."&Zip=".rawurlencode($Zip)."&TaxType=".rawurlencode($TaxType)."&LicenseKey=".rawurlencode($LicenseKey);
// Get cURL resource
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $TrialURL, CURLOPT_USERAGENT => 'Service Objects Fast Tax'));
//Https peer certification validation turned off
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT); //timeout in milliseconds
// Send the request & save response to $resp
$resp = curl_exec($curl);
$status = curl_getinfo($curl);
$decoded = json_decode($resp, TRUE);
if($resp == FALSE || (isset ($decoded['Error']) != NULL && $decoded['Error']['Number'] == 4) || (isset($status) && $status['http_code'] != 200))
{
// the first service has failed over
// create a new request to the backURL
$curl2 = curl_init();
curl_setopt_array($curl2, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $BackupURL, CURLOPT_USERAGENT => 'Service Objects Fast Tax'));
//Https peer certification validation turned off
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl2, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT); //timeout in milliseconds
// Send the request & save response to $resp
$resp = curl_exec($curl2);
$decoded = json_decode($resp, TRUE);
if($resp == false)
{
echo "<b> Both rest calls failed </b>";
curl_close($curl2);
return;
}
}
//Close request to clear up some resources
curl_close($curl);
$TrialURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=".rawurlencode($Address)."&Address2=".rawurlencode($Address2)."&City=".rawurlencode($City)."&State=".rawurlencode($State)."&Zip=".rawurlencode($Zip)."&TaxType=".rawurlencode($TaxType)."&LicenseKey=".rawurlencode($LicenseKey); // A trial license key is not compatible with the backup datacenter. // The backup url is provided with a production license key. $BackupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=".rawurlencode($Address)."&Address2=".rawurlencode($Address2)."&City=".rawurlencode($City)."&State=".rawurlencode($State)."&Zip=".rawurlencode($Zip)."&TaxType=".rawurlencode($TaxType)."&LicenseKey=".rawurlencode($LicenseKey); // Get cURL resource $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $TrialURL, CURLOPT_USERAGENT => 'Service Objects Fast Tax')); //Https peer certification validation turned off curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT); //timeout in milliseconds // Send the request & save response to $resp $resp = curl_exec($curl); $status = curl_getinfo($curl); $decoded = json_decode($resp, TRUE); if($resp == FALSE || (isset ($decoded['Error']) != NULL && $decoded['Error']['Number'] == 4) || (isset($status) && $status['http_code'] != 200)) { // the first service has failed over // create a new request to the backURL $curl2 = curl_init(); curl_setopt_array($curl2, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $BackupURL, CURLOPT_USERAGENT => 'Service Objects Fast Tax')); //Https peer certification validation turned off curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl2, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT); //timeout in milliseconds // Send the request & save response to $resp $resp = curl_exec($curl2); $decoded = json_decode($resp, TRUE); if($resp == false) { echo "<b> Both rest calls failed </b>"; curl_close($curl2); return; } } //Close request to clear up some resources curl_close($curl);
FastTax RoR Rest 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/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zipcode + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey)
backupURL = URI.encode("https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zipcode + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey)
#These are set to access the hash that is returned
@ftresponse ="BestMatchResponse"
@ftitems = "TaxInfoItems"
@ftbestmatch = "BestMatchTaxInfo"
@fterror = "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
if (!response[@ftresponse][@fterror].nil? && response[@ftresponse][@fterror]["Number"] == '4')
raise
else
processresults(response)
end
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 + " " + error.backtrace[0]
@displaydata = {"Error" => "A Big Error Occured"}
end
end
#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/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zipcode + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey)
backupURL = URI.encode("https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zipcode + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey)
#These are set to access the hash that is returned
@ftresponse ="BestMatchResponse"
@ftitems = "TaxInfoItems"
@ftbestmatch = "BestMatchTaxInfo"
@fterror = "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
if (!response[@ftresponse][@fterror].nil? && response[@ftresponse][@fterror]["Number"] == '4')
raise
else
processresults(response)
end
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 + " " + error.backtrace[0]
@displaydata = {"Error" => "A Big Error Occured"}
end
end
#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/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zipcode + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey) backupURL = URI.encode("https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zipcode + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey) #These are set to access the hash that is returned @ftresponse ="BestMatchResponse" @ftitems = "TaxInfoItems" @ftbestmatch = "BestMatchTaxInfo" @fterror = "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 if (!response[@ftresponse][@fterror].nil? && response[@ftresponse][@fterror]["Number"] == '4') raise else processresults(response) end 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 + " " + error.backtrace[0] @displaydata = {"Error" => "A Big Error Occured"} end end
FastTax Python Rest 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
inputs = {'Address': mAddress, 'Address2': mAddress2, 'City': mCity, 'State': mState, 'Zip': mZipCode, 'TaxType':mTaxType, '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['BestMatchResponse']:
#loops through the response from the service and prints the values to the screen.
if outputs['BestMatchResponse']['Error']['Number'] == "4":
raise Exception
else:
for key, value in outputs['BestMatchResponse']['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
for key, value in outputs['BestMatchResponse']['TaxInfoItems']['BestMatchTaxInfo'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
#Attempts to use the backupURL if the call to the primary URL failed
except:
try:
result = requests.get(backupURL, 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['BestMatchResponse']:
#loops through the response from the service and prints the values to the screen.
for key, value in outputs['BestMatchResponse']['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
for key, value in outputs['BestMatchResponse']['TaxInfoItems']['BestMatchTaxInfo'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
#Prints an error message if the primary and backup urls failed
except:
Label(swin.window, text='Error').pack()
print ("************************************************************************************************")
print ("************************************************************************************************")
print (response)
return
primaryURL = 'https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?'
backupURL = 'https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?'
#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, 'Address2': mAddress2, 'City': mCity, 'State': mState, 'Zip': mZipCode, 'TaxType':mTaxType, '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['BestMatchResponse']:
#loops through the response from the service and prints the values to the screen.
if outputs['BestMatchResponse']['Error']['Number'] == "4":
raise Exception
else:
for key, value in outputs['BestMatchResponse']['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
for key, value in outputs['BestMatchResponse']['TaxInfoItems']['BestMatchTaxInfo'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
#Attempts to use the backupURL if the call to the primary URL failed
except:
try:
result = requests.get(backupURL, 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['BestMatchResponse']:
#loops through the response from the service and prints the values to the screen.
for key, value in outputs['BestMatchResponse']['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
for key, value in outputs['BestMatchResponse']['TaxInfoItems']['BestMatchTaxInfo'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
#Prints an error message if the primary and backup urls failed
except:
Label(swin.window, text='Error').pack()
print ("************************************************************************************************")
print ("************************************************************************************************")
print (response)
return
primaryURL = 'https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?' backupURL = 'https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?' #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, 'Address2': mAddress2, 'City': mCity, 'State': mState, 'Zip': mZipCode, 'TaxType':mTaxType, '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['BestMatchResponse']: #loops through the response from the service and prints the values to the screen. if outputs['BestMatchResponse']['Error']['Number'] == "4": raise Exception else: for key, value in outputs['BestMatchResponse']['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 for key, value in outputs['BestMatchResponse']['TaxInfoItems']['BestMatchTaxInfo'].iteritems(): Label(swin.window, text=str(key) + " : " + str(value)).pack() #Attempts to use the backupURL if the call to the primary URL failed except: try: result = requests.get(backupURL, 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['BestMatchResponse']: #loops through the response from the service and prints the values to the screen. for key, value in outputs['BestMatchResponse']['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 for key, value in outputs['BestMatchResponse']['TaxInfoItems']['BestMatchTaxInfo'].iteritems(): Label(swin.window, text=str(key) + " : " + str(value)).pack() #Prints an error message if the primary and backup urls failed except: Label(swin.window, text='Error').pack() print ("************************************************************************************************") print ("************************************************************************************************") print (response) return
FastTax ColdFusion Rest Code Snippet
<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq "" >
<cftry>
<cfhttp url="#primaryURL#" method="get" result="response">
<cfset outputs = XmlParse(response.FileContent)>
<cfif (isNull(outputs) OR (!isNull(outputs.BestMatchResponse.Error) AND (outputs.BestMatchResponse.Error.Number is "10"))) >
<cfthrow message="BackupCall Used">
</cfif>
<cfdump var="#outputs#" >
<cfcatch >
<cftry>
<cfhttp url="#backupURL#" method="get" result="response">
<cfset outputs = XmlParse(outputs.FileContent)>
<cfdump var="#outputs#">
<cfcatch >
<cfoutput >
The Following Error Occured: #response.StatusCode#
</cfoutput>
</cfcatch>
</cftry>
</cfcatch>
</cftry>
</cfif>
<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq "" >
<cftry>
<cfset primaryURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=#Address#&Address2=#Address2#&City=#City#&State=#State#&Zip=#Zip#&TaxType=#TaxType#&LicenseKey=#LicenseKey#">
<cfhttp url="#primaryURL#" method="get" result="response">
<cfset outputs = XmlParse(response.FileContent)>
<cfif (isNull(outputs) OR (!isNull(outputs.BestMatchResponse.Error) AND (outputs.BestMatchResponse.Error.Number is "10"))) >
<cfthrow message="BackupCall Used">
</cfif>
<cfdump var="#outputs#" >
<cfcatch >
<cftry>
<cfset backupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=#Address#&Address2=#Address2#&City=#City#&State=#State#&Zip=#Zip#&TaxType=#TaxType#&LicenseKey=#LicenseKey#">
<cfhttp url="#backupURL#" method="get" result="response">
<cfset outputs = XmlParse(outputs.FileContent)>
<cfdump var="#outputs#">
<cfcatch >
<cfoutput >
The Following Error Occured: #response.StatusCode#
</cfoutput>
</cfcatch>
</cftry>
</cfcatch>
</cftry>
</cfif>
<!--Makes Request to web service ---> <cfIf isDefined("form.Action") AND Action neq "" > <cftry> <cfset primaryURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=#Address#&Address2=#Address2#&City=#City#&State=#State#&Zip=#Zip#&TaxType=#TaxType#&LicenseKey=#LicenseKey#"> <cfhttp url="#primaryURL#" method="get" result="response"> <cfset outputs = XmlParse(response.FileContent)> <cfif (isNull(outputs) OR (!isNull(outputs.BestMatchResponse.Error) AND (outputs.BestMatchResponse.Error.Number is "10"))) > <cfthrow message="BackupCall Used"> </cfif> <cfdump var="#outputs#" > <cfcatch > <cftry> <cfset backupURL = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=#Address#&Address2=#Address2#&City=#City#&State=#State#&Zip=#Zip#&TaxType=#TaxType#&LicenseKey=#LicenseKey#"> <cfhttp url="#backupURL#" method="get" result="response"> <cfset outputs = XmlParse(outputs.FileContent)> <cfdump var="#outputs#"> <cfcatch > <cfoutput > The Following Error Occured: #response.StatusCode# </cfoutput> </cfcatch> </cftry> </cfcatch> </cftry> </cfif>
FastTax 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/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zip + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey
Dim backupurl As String = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zip + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey
Dim wsresponse As BestMatchResponse = 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 = "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
Try
'encodes the URLs for the get Call. Set the primary and back urls as necessary
Dim primaryurl As String = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zip + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey
Dim backupurl As String = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zip + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey
Dim wsresponse As BestMatchResponse = 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 = "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
Try 'encodes the URLs for the get Call. Set the primary and back urls as necessary Dim primaryurl As String = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zip + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey Dim backupurl As String = "https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=" + address + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&Zip=" + zip + "&TaxType=" + taxtype + "&LicenseKey=" + licensekey Dim wsresponse As BestMatchResponse = 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 = "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
FastTax TSQL Rest Code Snippet
SET @address = CASE WHEN @address is NULL THEN ' ' ELSE @address END
SET @address2 = CASE WHEN @address2 is NULL THEN ' ' ELSE @address2 END
SET @city = CASE WHEN @city is NULL THEN ' ' ELSE @city END
SET @state = CASE WHEN @state is NULL THEN ' ' ELSE @state END
SET @zip = CASE WHEN @zip is NULL THEN ' ' ELSE @zip END
SET @taxtype = CASE WHEN @taxtype is NULL THEN ' ' ELSE @taxtype END
SET @key = CASE WHEN @key is NULL THEN ' ' ELSE @key END
SET @isLiveKey = CASE WHEN @isLiveKey is NULL THEN 1 ELSE @isLiveKey END
--If a production key is purchased, this will execute the failover
IF @isLiveKey = 1
BEGIN
SET @sUrl = 'https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&Zip=' + @zip + '&TaxType=' + @taxtype + '&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/ft/web.svc/JSON/GetBestMatch?Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&Zip=' + @zip + '&TaxType=' + @taxtype + '&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
SET @address = CASE WHEN @address is NULL THEN ' ' ELSE @address END
SET @address2 = CASE WHEN @address2 is NULL THEN ' ' ELSE @address2 END
SET @city = CASE WHEN @city is NULL THEN ' ' ELSE @city END
SET @state = CASE WHEN @state is NULL THEN ' ' ELSE @state END
SET @zip = CASE WHEN @zip is NULL THEN ' ' ELSE @zip END
SET @taxtype = CASE WHEN @taxtype is NULL THEN ' ' ELSE @taxtype END
SET @key = CASE WHEN @key is NULL THEN ' ' ELSE @key END
SET @isLiveKey = CASE WHEN @isLiveKey is NULL THEN 1 ELSE @isLiveKey END
--If a production key is purchased, this will execute the failover
IF @isLiveKey = 1
BEGIN
SET @sUrl = 'https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&Zip=' + @zip + '&TaxType=' + @taxtype + '&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/ft/web.svc/JSON/GetBestMatch?Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&Zip=' + @zip + '&TaxType=' + @taxtype + '&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
SET @address = CASE WHEN @address is NULL THEN ' ' ELSE @address END SET @address2 = CASE WHEN @address2 is NULL THEN ' ' ELSE @address2 END SET @city = CASE WHEN @city is NULL THEN ' ' ELSE @city END SET @state = CASE WHEN @state is NULL THEN ' ' ELSE @state END SET @zip = CASE WHEN @zip is NULL THEN ' ' ELSE @zip END SET @taxtype = CASE WHEN @taxtype is NULL THEN ' ' ELSE @taxtype END SET @key = CASE WHEN @key is NULL THEN ' ' ELSE @key END SET @isLiveKey = CASE WHEN @isLiveKey is NULL THEN 1 ELSE @isLiveKey END --If a production key is purchased, this will execute the failover IF @isLiveKey = 1 BEGIN SET @sUrl = 'https://trial.serviceobjects.com/ft/web.svc/JSON/GetBestMatch?Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&Zip=' + @zip + '&TaxType=' + @taxtype + '&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/ft/web.svc/JSON/GetBestMatch?Address=' + @address + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&Zip=' + @zip + '&TaxType=' + @taxtype + '&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