0

I tried using example API but seems some of the parameters missing. This is the API I tried.

        public W_AddressStateCity GetAddressStateCityInfo(W_CustomerAddress oAddress)
    {
        W_AddressStateCity oAddStateCity = new W_AddressStateCity();
        var client = new ClientBuilder(AuthID, AuthToken).BuildUsStreetApiClient();

        var lookup = new Lookup
        {
            Street = oAddress.AddressStreetAddress1,
            Street2 = oAddress.AddressStreetAddress2,
            City = oAddress.AddressCity,
            State = oAddress.AddressState,
            ZipCode = oAddress.AddressZipCode
        };

        try
        {
            client.Send(lookup);
        }
        catch (SmartyException ex)
        {
            // Console.WriteLine(ex.Message);
            //  Console.WriteLine(ex.StackTrace);
        }
        var candidates = lookup.Result;

        oAddStateCity.Country = candidates[0].Metadata.Country;
        oAddStateCity.State = candidates[0].Metadata.State;
        oAddStateCity.County = candidates[0].Metadata.CountyName;
        oAddStateCity.City = candidates[0].Metadata.City;

        return oAddStateCity;
    }

Only CountyName is available in candidates. The address is always validated before fed into this API. How I could read Country, State and City ? I want to read that information from the API, nit from my provided address.

PCG
  • 2,049
  • 5
  • 24
  • 42

1 Answers1

1

I assume you are referring to the "US Street Address API". SmartyStreets has multiple APIs.

If you look at the US Street Address API documentation on the SmartyStreets site you can see an Example Output - Valid Address section that shows you the common data that is returned.

In the "components" object you can see the city_name and state_abbreviation. If you look in the "metadata" object you can see the county_name.

If you are hitting the "US Street Address API" then all addresses will have "USA" as the country. There is no need to return that. If you use the "International Street Address API" you will have country information included.

Michael Whatcott
  • 5,603
  • 6
  • 36
  • 50
SunSparc
  • 1,812
  • 2
  • 23
  • 47