Square Go SDK Quickstart

Learn how to quickly set up and test the Square Go 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 the following:

    • Go - Square supports Go version 1.18 or later.
Link to section

Create a project

  1. Open a new terminal window.

  2. Create a new directory for your project, navigate to that directory, and initialize a new Go module.

    mkdir quickstart cd quickstart go mod init quickstart
  3. Run the following command to use the Square Go library in your module:

    go get github.com/square/square-go-sdk
Link to section

Write code

  1. In your project directory, create a new file named quickstart.go with the following content:

This code does the following:

  1. Creates a new squareclient object with your Square access token. For more information, see Set your Square credentials.
  2. Calls the Locations.List method.
  3. If the request is successful, your Square location details are printed in the terminal window.
Link to section

Set your Square credentials

The Go code in this Quickstart reads your Square Sandbox access token from the SQUARE_ACCESS_TOKEN environment variable. This helps avoid the use of hardcoded credentials in the code.

For the following commands, replace yourSandboxAccessToken with your Square Sandbox access token:

Link to section

Linux or macOS

export SQUARE_ACCESS_TOKEN=yourSandboxAccessToken
Link to section

Windows: PowerShell

Set-item -Path Env:SQUARE_ACCESS_TOKEN -Value yourSandboxAccessToken
Link to section

Windows: Command shell

set SQUARE_ACCESS_TOKEN=yourSandboxAccessToken
Link to section

Run the application

  1. In your quickstart directory, run the go build command to compile the code.
  2. Run your program with ./quickstart.
  3. Verify the result. You should see at least one location, even if you just created your Square account.