Square .NET SDK Quickstart

Learn how to quickly set up and test the Square .NET SDK.

Link to section

Prepare for the Quickstart

Before you begin, you need a Square account and account credentials. You use the Square Sandbox for the Quickstart exercise.

  1. Create a Square account and an application. For more information, see Create an Account and Application.
  2. Get a Sandbox access token from the Developer Console. For more information, see Get a personal access token.
  3. Install .NET if you don't already have it on your computer.

You can now use one of the following workflows depending on whether you're using Visual Studio.

Note

If you prefer to skip the following setup steps, download the Square .NET SDK Quickstart sample and follow the instructions in the README.

Link to section

Create a project

  1. Open a new terminal window.

  2. Find or create a new folder for your .NET project.

  3. In that folder, run the following command to create a new .NET project:

    dotnet new console --name Quickstart
  4. Add an application settings file to the project to store credentials. Go to the newly created Quickstart folder and add the following appsettings.json file, replacing YOUR-SANDBOX-ACCESS-TOKEN with your Sandbox access token:

    { "AppSettings": { "AccessToken": "YOUR-SANDBOX-ACCESS-TOKEN" } }
  5. Run the following commands to install the necessary packages:

    dotnet add package Square dotnet add package Microsoft.Extensions.Configuration.Json dotnet add package Microsoft.Extensions.Configuration

    The Microsoft.Extensions.Configuration and package Microsoft.Extensions.Configuration.Json packages are used to manage the application settings file.

Link to section

Write code

  1. In your Quickstart folder, find and open Program.cs in your preferred editor.

  2. Replace the contents with the following code and save the file:

    This code does the following:

    • Reads your Square Sandbox access token from the appsettings.json file.
    • Creates a new client using the access token.
    • Calls the ListAsync method on the Locations API to retrieve the locations for your Square account.
    • If the request is successful, the code prints the location information in the terminal.
Link to section

Run the application

Run the following command:

dotnet run

You should see at least one location listed (Square creates one Sandbox location when you create a Square account).