Learn how to quickly set up and test the Square .NET SDK.
Before you begin, you need a Square account and account credentials. You use the Square Sandbox for the Quickstart exercise.
- Create a Square account and an application. For more information, see Create an Account and Application.
- Get a Sandbox access token from the Developer Dashboard. For more information, see Make your First API Call.
You can now follow one of the following workflows depending on whether you're using Visual Studio.
Use the following steps to create a project if you're using a non-Windows computer and don't use Visual Studio. These steps use the .NET command-line interface. Make sure you have .NET installed on your computer. For example, if you're using a Mac, see Install .NET on macOS.
Open a new terminal window. Find or create an operating system folder under which you can create a .NET project.
In that folder, run the following command to create the .NET project:
Don't add your credentials to the source file. You add an application settings file to the project to store credentials.
Go to the newly created ExploreLocationsAPI folder and add the following appsettings.json file:
See the following example:
Update the JSON file by providing your Sandbox access token.
Run the following commands to install the NuGet packages from the NuGet package manager:
package Microsoft.Extensions.Configuration.Jsonpackages are used to manage the application settings file (such as read credentials).
In the ExploreLocationsAPI folder, find and open Program.cs in your code editor.
Replace the contents with the following code and save the file:
This code does the following:
- Reads your Square access token from the appsettings.json file.
- Creates a SquareClient using the access token.
- Calls the ListLocationsAsync method to retrieve the locations.
If the request is successful, the code prints the location information on the terminal.
Update the code to provide the full path of the appsettings.json file.
Run the following command:
You should see at least one location (Square creates one location when you create a Square account).
You perform this Quickstart exercise on a Windows computer using Visual Studio and .NET Core. Make sure you have the following:
- Microsoft Visual Studio.
- Microsoft .NET Standard 2.0 or later. This is typically included by default when installing a recent version of Visual Studio. For more information, see Install .NET on Windows.
Open Visual Studio and create a new project using the C# Console Application template. Name the project ExploreLocationsAPI.
After the project loads, right-click the project, choose Add, and then choose NuGet Packages.
Search the following NuGet packages and install them in the project:
Add an appsettings.json file to the project.
Right-click the project, choose Add, choose New File, and then choose Empty text file. Specify the file name as appsettings.json.
Add the following JSON:
Update the preceding JSON by providing your Sandbox access token.
Update the file properties. Right-click appsettings.json, and then choose Properties. In the Copy to Output Directory drop-down list, choose Copy if newer.
In the ExploreCustomersAPI project, find and open Program.cs.
Replace the contents with the following code:
Save the file.
This code does the following:
- Build and run the application.
- Verify the result. You should see at least one location (Square creates one location when you create a Square account).
You can explore one of the following paths:
- Explore the .NET SDK and try examples on your own. For more information, see SDK reference library on GitHub.
- Learn more introductory information about using the .NET SDK.