SmartyStreets Address Validation PHP Example?
Asked Answered
S

3

6

Can I get a sample PHP code example which calls SmartyStreets LiveAddress API for address validation?

Silin answered 22/5, 2012 at 2:0 Comment(0)
A
3

Sure -- we have sample code at our GitHub repository. There's 3 examples there:

  1. A request to our API using cURL (can handle many addresses at once)
  2. A GET request. Easy, but only supports one address per request
  3. A "SLAP" (Single-Line Address Processing) example which shows how to verify an address if it's not already split into components like street, city, state, etc.

If you have any further questions, I'd be happy to help; I wrote these examples.

Anastase answered 22/5, 2012 at 2:35 Comment(16)
Thank you very much. I will jump into these and get back to you if I have any doubts.Silin
You're welcome. Don't forget to click the checkmark and mark this answer as "accepted" if it satisfies your question.Anastase
Ok. I used the get.php file since I need to pass only one address at a time and it works absolutely fine. Thank you very much for that. Now I have some specific questions.Silin
Question1: If I pass an invalid address, I am getting a blank array as response. Is it the only way I will understand that address is invalid or the API should return some status flag which says address is valid or not?Silin
Question2: Like UPS address API does SmartyStreet API can return multiple matching address for a given input address? If an invalid input is passed as address does SmartyStreet API returns back possible list of correct address like Google does, so that user can correct their address based on the suggestion returned by SmartyStreet API?Silin
Question3: I am passing only StreetAddress and ZipCode and the API is working very nice. However if I pass only ZipCode(not even street address) I am not getting any response back. Does it mean SmartyStreet API doesn't support address validation only if ZipCode is passed as input parameter?Silin
Q1: Yes, invalid addresses return 0 results because the API will only return real, valid addresses. Q2: If an address is ambiguous/near-valid, we return all possible, but valid, results. (e.g. try 100, New York, NY). Q3: Not currently, but in a future release it will. Our core business expertise is verifying addresses, not supplying ZIP code data by itself. ZIP codes can span multiple cities, counties, and states, so it's more complicated than you may think, but additional features like these are on our roadmap.Anastase
@Silin Q3: What kind of information would you like to get back when you enter ZIP Code only? Are you looking for city/state based on the ZIP code?Ultramodern
@Silin Q2: If you submit 101 North Main for the address and there is a 103 and 99 but no 101 on that street, we do not inform you of the other addresses. Federal privacy policy restricts the data that we can provide you. We can give a yes or a no for an address that is entered but we can't give you the surrounding addresses. Think of it like a credit card. If you enter your credit card number incorrectly on a website, do you really want it to say "did you mean" and give you a list of similar numbers?Ultramodern
@Silin Q2: GoogleMaps does autosuggest (which we will also be doing shortly) but you still have to enter the right house number. For example, 1402 West Center St Orem UT 84057. If you start typing in that address, "1402 West Center" it will show you options. However, it will not show you that there is a 1401 or a 1403 on that street.Ultramodern
@Jeffry & Matt - thank you very much for your detailed responseSilin
1. When I pass only zipcode I need only a yes/no or valid/invalid response which will tell me whether the Zipcode is valid or not. For example if I have a Zipcode field in user registration form I want to validate whether the Zipcode entered by the user is valid or not. If he supplies a junk Zipcode I want to block registration.Silin
2. Street Name issue - I am not much concerned about the street number. Say If I supply zipcode and street name as Orange Street then I was expecting like google map SmartyStreet might suggest address like Orange Street, Orlando Street, Oriental Street like Google Map API. In that case I can show all the possible address in a list for user to select just like it happens in Google map.Silin
@Jeffry & Matt - kindly let me know if SmartyStreet has any plan in releasing API which can validate a zipcode.Silin
We do, yes, but we don't have a hard timeline for its deployment yet. There's a lot of great things coming and improving in the meantime. Stay tuned!Anastase
@Silin Did you know we deployed the ZIP code API a while ago? Now you can pass in cities/states/zips instead of street addresses.Anastase
H
0

If you are developing SmartyStreet code on a test system that doesn't have a secure certificate, you can add this line to disable the certificate test:

if ($bTestSystem) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
Henden answered 17/4, 2016 at 18:35 Comment(0)
T
-1

Smarty streets uses the same approach as many other solutions. The user enters an Address and then a lookup is performed and if the address is not found the user is presented a list of valid addresses to select. This is a slower approach that may not be ideal.

A newer approach that may be a better option comes from Addrexx. The Addrexx solutions allows users to autoselect their information from dropdown lists. This speeds the process on entering personal information. Full disclosure: I am a developer at Addrexx. Addrexx is a SaaS that includes complete integration packages for salesforce, magento, big commerce and many more platforms.

You can see the Addrexx approach at http://addrexx.com/ecommerce.html.

Threephase answered 20/12, 2013 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.