Build with the Labor API
Use the Labor API to create shift records that capture the start, breaks, and end of a team member's shift and the hourly rate for the shift.
This topic provides step-by-step guidance for integrating with the Labor API. For information about how the Labor API works, see How It Works.
To use the Labor API, the following must be true:
You have a Square account. Create a Square account in minutes if you do not already have one.
You have added team members to at least one location in the Seller Dashboard.
This topic also makes the following assumptions:
The Seller Dashboard for your account has at least one active team member.
You have assigned at least one wage type per team member in the Seller Dashboard.
Did you know?
You can assign wage types to a team member by using the Team API.
To use the steps in this topic, you need:
You need a valid access token. You should test with Sandbox credentials whenever possible. For more information, see Access Tokens and Other Square Credentials.
An active location ID. Copy a developer account location ID from the Locations page of your Square application in the Developer Dashboard or set the Developer Dashboard to Sandbox mode and then copy a Sandbox location ID.
This topic walks you through the process of starting and ending a team member shift:
Start a shift
Configure the Labor API with a valid access token and location ID.
Get a team member ID.
Get the wage type for the job to be done on the shift.
Check for a previous open shift record for the team member.
Create and send a CreateShift request to create a new shift record and start a shift.
End a shift
Search for the open shift record.
Update the record with an end time to end it.
Before you can use the Labor API, you must set the location ID where the API is used and then get an access token to authorize the API to access Shift
and TeamMember
resources for that location.
Follow these steps to get the access token and location ID used in this walkthrough.
Sign in to the Developer Dashboard and open your application. If you do not have a Square account, see Get Started to learn how to create an account and an application.
Get your Sandbox access token:
At the top of the page, in the Sandbox and Production toggle, choose Sandbox.
On the Credentials page, under Sandbox Access Token, choose Show and then copy the token. All Square API requests require an access token for authorization. This personal access token grants full access to the Sandbox resources in your account.
Important
The Sandbox access token is a secure secret. Do not share it with anyone.
Get your location ID:
In the left pane, choose Locations.
On the Locations page, keep Default Test Account selected and copy a location ID.
Note
To retrieve location IDs programmatically, call ListLocations.
If you are using an OAuth access token, request EMPLOYEES_READ
and TIMECARDS_WRITE
permissions.
Use the Team API to retrieve a list of active team members for a location and select a team member from the list. Use the following logic to get active team members for a location:
The response carries an array of TeamMember
objects representing the active team members for the specified location:
Use the Team API to get the wage settings of the team member.
A TeamMember can have multiple wage types and job titles. To assign the correct wage to a shift, get all the WageSetting objects for the team member and find the wage type for the job that the team member is performing in this shift.
Did you know?
The first WageSetting
in the set of returned items is the default team member wage. Use the default wage unless you are choosing a WageSetting
based on a matching job title
.
The response carries an array of the WageSetting objects associated with a team member ID:
A new shift record cannot be created for a team member until the previous shift record is closed.
The following shift search request asks for a set of shift records with the following instructions:
Shifts for one specified team member.
At a specified location.
With shifts whose
status
isOPEN
.
This filter always returns zero or one Shift
record. A team member can have a maximum of one open shift.
The response to the shift search request is an empty object if the team member does not have an OPEN
shift:
To create a new shift, use the location ID, team member ID, and WageSetting
hourly rate to set values in a new ShiftWage
. The shift start_at
field can be set to local time or GMT. If you use GMT, the Square Labor endpoint calculates the local time based on the location of the shift.
Use the following logic to create the shift.
Important
You must include a wage
object with a pay rate so that the labor cost is recorded. If you do not include a wage
, there is no pay amount associated with the shift record.
The job title and compensation rate that may be associated with the team member is not used as a default value for the wage in the created shift.
Get the open shift for the team member by using the example in Step 3.
The response to the shift search request is an array of Shift
objects that match the filter criteria:
Before you POST the updated shift, look for an array of Break objects that are present if the employee took any breaks during the shift. If you find
these object, confirm that they contain end_at
properties and that those properties are not null.
The response is an updated version of the shift object with a CLOSED
status and an incremented version number:
If you need more assistance, contact Developer Support or ask for help in the Developer Forums.