The Square Connect .NET SDK is retired (EOL) as of 2019-12-17 and will no longer receive bug fixes or product updates. To continue receiving API and SDK improvements, please follow the instructions below to migrate to the new Square .NET SDK.
The old Connect SDK documentation is available under the
/docs folder.
Follow the instructions below to migrate your apps from the deprecated
Square.Connect library to the new Square library.
Replace Square.Connect with the new Square package and update the version.
- Change all instances of
using Square.Connect.Apitousing Square. - Change all instances of
using Square.Connect.Modeltousing Square.Models. - Remove all instances of
using Square.Connect.Client. - Add a reference to
using Square.Exceptionsto anything that calls an endpoint. - Update client instantiation to follow the method outlined below.
To simplify your code, we also recommend that you use method chaining to access APIs instead of explicitly instantiating multiple clients.
SquareClientsquare=newSquareClient.Builder().Environment(Square.Environment.Sandbox).AccessToken("YOUR_SANDBOX_ACCESS_TOKEN").Build();// e.g to fetch a list of locationsvarresponse=square.LocationsApi.ListLocationsAsync();As a specific example, consider the code used to create a new customer
profile with the following CreateCustomerRequest object:
varbodyAddress=newAddress.Builder().AddressLine1("500 Electric Ave").AddressLine2("Suite 600").Locality("New York").AdministrativeDistrictLevel1("NY").PostalCode("10003").Country("US").Build();varbody=newCreateCustomerRequest.Builder().GivenName("Amelia").FamilyName("Earhart").EmailAddress("Amelia.Earhart@example.com").Address(bodyAddress).PhoneNumber("1-212-555-4240").ReferenceId("YOUR_REFERENCE_ID").Note("a customer").Build();With the deprecated Square.Connect library, this is how you instantiate a client
for the Customers API, format the request, and call the endpoint:
usingSystem;usingSystem.Diagnostics;usingSquare.Connect.Api;usingSquare.Connect.Client;usingSquare.Connect.Model;// Instantiate the clientvarconfiguration=newConfiguration(newApiClient("https://connect.squareupsandbox.com"));configuration.AccessToken="YOUR_SANDBOX_ACCESS_TOKEN";varcustomersApi=newCustomersApi(configuration);// Call the endpoint and handle the responsetry{// CreateCustomerCreateCustomerResponseresult=customersApi.CreateCustomer(body);Debug.WriteLine(result);}catch(Exceptione){Debug.Print("Exception when calling CustomersApi.CreateCustomer: "+e.Message);}Now consider equivalent code using the new Square library:
usingSquare;usingSquare.Models;usingSquare.Exceptions;// Instantiate the clientSquareClientsquare=newSquareClient.Builder().Environment(Square.Environment.Sandbox).AccessToken("YOUR_SQUARE_ACCESS_TOKEN").Build();// Call the endpoint and handle the responsetry{CreateCustomerResponseresult=square.CustomersApi.CreateCustomerAsync(body).Result;// Business logic}catch(APIExceptione){// Error Handling};That's it!
What was once a multi-block process can be handled in 1 line of code. Migrating
to the Square library reduces boilerplate and lets you focus on the parts of
your code that really matter.
Please join us in our Square developer community if you have any questions!