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/Mono framework (like C#).
  2. The minimum supported .NET framework is version 4.5.
  3. Build enough of the project to realize that you now need an address verification component.
  4. Wisely conclude that you don't want to build your own address verification component.
  5. Realize that SmartyStreets has already created an address verification component.
  6. 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 and Xamarin both 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 = Environment.GetEnvironmentVariable("SMARTY_AUTH_ID");
			var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
			var client = new ClientBuilder(authId, authToken).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);
		}
	}
}