Getting Started with the Square API
Get introduced to Square and the Square API.
We'll cover the following
Square offers digital payments and financial services to its customers. The idea for Square was conceived by Jack Dorsey to help his friend, Jim McKelvey, complete some sales. Square helps businesses of almost all types to expand their outreach.
Square offers a wide range of business tools and equitable loans to its customers. They have a wide range of customers ranging from retail companies to beauty professionals. With a broad set of flexible tools, we only need to pay for the tools we need. They also work with third-party services to enhance our retail experience.
Square API
The Square API is structured to cover almost all core business workflows. For example, creating customer records, taking orders, making payments, creating invoices, and issuing refunds.
Square provides a RESTful API. Therefore, whether you’re a beginner or have worked with an API before, learning the Square API should not be a problem. The scope of this course covers the following Square APIs:
The Square developer account
Before we begin the course, let’s first create a Square account that will enable us to test all Square APIs and start developing. To create a Square developer account, follow these steps:
- Go to the Square Developer Sign-up page, enter the required information (first name, last name, email, password, and the country where the account is being created) and click “Continue.” Square creates an account and redirects to the next page.
- On the next page, enter the business name and click “Continue.”
- The next page asks for our coding preference. You can select Node.js and click “Continue” or skip this step by clicking “Skip.”
- Enter the name of the application, “Test Application 1,” for instance, in the “Application name” box. Click the checkbox to agree to the terms of service, and click “Continue.”
- The next page collects some information regarding business needs and use cases. The contents of this course somewhat match the first two options, i.e., “Accept payments” and “Manage and fulfill orders.” You can also skip this step by clicking “Skip.”
- The last step inquires about the audience of our application. You can select “Myself” or skip this step.
- Finally, we’ll be redirected to the credentials page. Get the Access token by clicking the “Show” button under “Sandbox Access token.”
After getting the Access token, save it in the widget below. To do so:
- Click the “Edit” button in the following widget.
- Paste the value of the Access token in the
ACCESS_TOKEN
field. - Click “Save.”
To check if everything is up and running, run the following code, which calls a simple endpoint of the Square API. Don’t worry about the code for now. We’ll discuss this code in detail later.
const url = new URL('https://connect.squareupsandbox.com/v2/merchants');const options = {method: 'GET',headers: {'Authorization': 'Bearer {{ACCESS_TOKEN}}','Content-Type': 'application/json'},};async function validateAccessToken() {try {const response = await fetch(url, options);// Custom function for printing the API responseprintResponse(response);} catch (error) {console.log(`Error: ${err}`);}}validateAccessToken();