Documentation

 

SmartyStreets .NET SDK

If you want to access our APIs (other than the Download API) from a C#, F#, or Visual Basic application, the SmartyStreets .NET SDK can make it a lot easier. Our .NET SDK includes ready-made data structures and takes care of all the gritty, low-level HTTP intricacies for you.

Contents

  1. Requirements
  2. How to Get It
    1. NuGet
    2. Download the Source Code
  3. How to Use It
    1. Demo
    2. Examples
  4. API Reference Material

Requirements

  1. Decide to build a software project using a programming language compatible with the .NET Framework v3.5 (or later), .NET Core 2.0, .NET Standard 2.0, or Mono (like C#).
  2. Build enough of the project to realize that you now need an address verification component.
  3. Wisely conclude that you don't want to build your own address verification component.
  4. Realize that SmartyStreets has already created an address verification component.
  5. Congratulations! You are now ready to use the SmartyStreets .NET SDK.

How to Get It

NuGet

The easiest way to install this SDK is by using NuGet. Visual Studio, Xamarin, and Project Rider all have NuGet plugins, but you can also run the following command in the Package Manager Console:

PM> Install-Package smartystreets-dotnet-sdk

Or you can run this command in the command line:

nuget install smartystreets-dotnet-sdk

Download the Source Code

You can download the source code from the SmartyStreets .NET SDK repository on Github.

Use the source, Luke!

How to Use It

Demo

Examples

Here is an example to show how to use our .NET library/SDK. Click here to view the other examples.

namespace Examples
{
	using System;
	using System.IO;
	using SmartyStreets;
	using SmartyStreets.USStreetApi;

	public class USStreetSingleAddressExample
	{
		public static void Run()
		{
			var authId = "Your SmartyStreets Auth ID here";
			var authToken = "Your SmartyStreets Auth Token here";

			// We recommend storing your keys in environment variables instead---it's safer!
			// var authId = Environment.GetEnvironmentVariable("SMARTY_AUTH_ID");
			// var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");

			var client = new ClientBuilder(authId, authToken)
						// uncomment the line below to point to the specified proxy.
						// .ViaProxy("http://localhost:8080", "username", "password")
						.BuildUsStreetApiClient();

			var lookup = new Lookup
			{
				Street = "1600 Amphitheatre Pkwy",
				City = "Mountain View",
				State = "CA"
			};

			try
			{
				client.Send(lookup);
			}
			catch (SmartyException ex)
			{
				Console.WriteLine(ex.Message);
				Console.WriteLine(ex.StackTrace);
			}
			catch (IOException ex)
			{
				Console.WriteLine(ex.StackTrace);
			}

			var candidates = lookup.Result;

			if (candidates.Count == 0)
			{
				Console.WriteLine("No candidates. This means the address is not valid.");
				return;
			}

			var firstCandidate = candidates[0];

			Console.WriteLine("Address is valid. (There is at least one candidate)\n");
			Console.WriteLine("ZIP Code: " + firstCandidate.Components.ZipCode);
			Console.WriteLine("County: " + firstCandidate.Metadata.CountyName);
			Console.WriteLine("Latitude: " + firstCandidate.Metadata.Latitude);
			Console.WriteLine("Longitude: " + firstCandidate.Metadata.Longitude);
		}
	}
}
This site uses cookies for analytics, personalized content, and ads. By continuing to browse this site, you agree to this use.