- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- TSQL
Phone Append 2 C# Rest Code Snippet
string mainURL = WEB_SERVICE_PRIMARY_URL + state + "/" + city + "/" + postalcode + "/" + address + "/" + name + "/" + isbusiness + "/" + licensekey + "?format=json"; PA2Response 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(PA2Response)); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); result = objResponse as PA2Response; //processing result if (result.error == null) { //process result } else { //process error }
Phone Append 2 Java Rest Code Snippet
PA2Response.PhoneInfo result = null; PA2Response.Error error = null; PA2RestClient PA2Client = new PA2RestClient(); PA2Response result = PA2Client.CompositePhoneAppend(name, addr, city, state, postalCode, isBusiness, licenseKey); if (result != null) { error = result.Error; info = result.Phoneinfo; } //Process Results if (error == null) { //DOTS Address Phone Append Results } //Process Errors else{ } //DOTS Phone Append Error }
Phone Append 2 PHP Rest Code Snippets
$URL = "https://trial.serviceobjects.com/PA2/api.svc/CompositePhoneInfo/".rawurlencode($State)."/".rawurlencode($City)."/".rawurlencode($PostalCode)."/".rawurlencode($Address)."/".rawurlencode($Name)."/".rawurlencode($isBusiness)."/".rawurlencode($LicenseKey)."?format=json"; // Get cURL resource $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Phone Append 2')); 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(json_decode($resp, TRUE)), RecursiveIteratorIterator::SELF_FIRST); foreach ($jsonIterator as $key => $val) { if(is_array($val)) { echo "Phone Append 2 Results"; } else { echo "$key"; echo "$val"; } }
Phone Append 2 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 name = @request.name address = @request.address city = @request.city state = @request.state postalcode = @request.postalcode isbusiness = @request.isbusiness licensekey = @request.licensekey #Set Primary and Backup URLs as needed primaryURL = URI.encode("https://trial.serviceobjects.com/PA2/api.svc/CompositePhoneAppend?Name="+name+"&Address="+address+"&City="+city+"&State="+state+"&PostalCode="+postalcode+"&isBusiness="+isbusiness+"&LicenseKey="+licensekey) backupURL = URI.encode("https://trial.serviceobjects.com/PA2/api.svc/CompositePhoneAppend?State="+ state+"&City="+city+"&PostalCode="+postalcode+"&Address="+address+"&Name="+name+"&isBusiness="+isbusiness+"&LicenseKey="+licensekey) #These are set to access the hash that is returned @phoneresponse = "PhoneInfoResponse" @phoneinfo = "PhoneInfo" @error = "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 from HTTParty and the hash key values to this method 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 end end end private def processresults(response) #Processes Error Response from rest Client #Processes Valid response from rest client end
Phone Append 2 Python Code Snippet
mFullName = FullName.get() if mFullName is None or mFullName == "": mFullName = " " mFirstName = FirstName.get() if mFirstName is None or mFirstName == "": mFirstName = " " mLastName = LastName.get() if mLastName is None or mLastName == "": mLastName = " " mAddress = Address.get() if mAddress is None or mAddress == "": mAddress = " " 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 = " " primaryURL = 'https://trial.serviceobjects.com/P2/api.svc/PhoneAppend?' backupURL = 'https://trial.serviceobjects.com/PA2/api.svc/PhoneAppend?' #The Requests package allows the user to format the path parameters like so instead of having to manually insert them into the URL inputs = {'FullName': mFullName, 'FirstName': mFirstName, 'LastName':mLastName, '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) #Handel response and check for errors #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) #Handel response and check for errors #Displays an error message if the backup url failed. except: Label(swin.window, text='Error').pack() print (result)
Phone Append 2 ColdFusion Rest Snippet
<!--Makes Request to web service ---> <cfscript> try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/pa2/api.svc?WSDL"); outputs = wsresponse.phoneAppend("#FullName#", "#FirstName#", "#LastName#", "#Address#", "#City#", "#State#", "#PostalCode#" ,"#LicenseKey#"); writedump(outputs.getPhoneInfo()); } } catch(any Exception) { try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/pa2/api.svc?WSDL"); outputs = wsresponse.phoneAppend("#FullName#", "#FirstName#", "#LastName#", "#Address#", "#City#", "#State#", "#PostalCode#" ,"#LicenseKey#"); } } catch(any Exception) { writeoutput("An Error Has Occured. Please Reload and try again #Exception.message#"); } } </cfscript>
Phone Append 2 VB Rest 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/PA2/api.svc/PhoneAppend?State=" & state + "&City=" + city + "&PostalCode=" + postalcode + "&Address=" + address + "&FullName=" + fullname + "&LastName=" + lastname + "&FirstName=" + firstname + "&LicenseKey=" & licensekey Dim backupurl As String = "https://trial.serviceobjects.com/PA2/api.svc/PhoneAppend?State=" & state + "&City=" + city + "&PostalCode=" + postalcode + "&Address=" + address + "&FullName=" + fullname + "&LastName=" + lastname + "&FirstName=" + firstname + "&LicenseKey=" & licensekey Dim wsresponse As PA2Response.PhoneInfoResponse = 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].Type IsNot Nothing Then ProcessErrorResponse(wsresponse.[Error]) Else ProcessSuccessfulResponse(wsresponse) End If
Phone Append 2 TSQL Rest Code Snippet
BEGIN SET @sUrl = 'https://sws.serviceobjects.com/pa2/api.svc/PhoneAppend?FullName=' + @fullname + '&FirstName=' + @firstname + '&LastName=' + @lastname + '&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://swsbackup.serviceobjects.com/pa2/api.svc/PhoneAppend?FullName=' + @fullname + '&FirstName=' + @firstname + '&LastName=' + @lastname + '&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