Getting started with employee shift scheduling
This guide introduces Timefold’s Employee Shift Scheduling model and walks you through the steps to use Timefold Platform to create an employee shift schedule.
The steps in this guide can be completed in under 10 minutes.
Prerequisites
To follow this guide, you need:
-
An active Timefold Platform account
-
An API client (optional but recommended)
Request a trial
To request for a trial with Timefold Platform:
-
Navigate to https://app.timefold.ai.
-
Click Log in.
-
Click Sign up.
Either enter the email address and password you want to register with and click continue or select one of the federated log-in options and follow the prompts.
-
Verify your email address.
-
Click Request a trial.
A member of our team will contact you to arrange a trial.
1. Test run
Complete an employee shift scheduling test run in Timefold Platform.
-
From the Models page, select Employee Shift Scheduling.
-
Click + New run.
-
Select Basic and click Run.
When the test run begins you will see the Overview page which shows the constraints score changing over the length of the model run, the timeline of the run, input metrics, and details about the constraints.
Click Visualizations to view visualizations of the solution.
2. Employee shift scheduling hello world example
This hello world uses an example with one employee and one shift to demonstrate the process of requesting and retrieving a solution from Timefold’s Employee Shift Scheduling model.
In the example, Beth is a security guard who works the night shift at a medical clinic.
2.1. Create a dataset
A dataset for the Employee Shift Scheduling model must include information about the shifts that need to be covered and the employees who are available to work those shifts. The dataset can include information about the time and location of the shift, the required skills necessary of the person who works the shift, and the employees' preferred shifts.
You create your dataset using our predefined model schema which follows the OpenAPI specification.
See API Spec for more information.
The modelInput object contains the dataset to be scheduled, which, at a minimum, must include employees and shifts.
{
"modelInput": {
"employees": [
{
"id": "Beth",
"skills": [
{
"id": "Security guard"
}
]
}
],
"shifts": [
{
"id": "Mon Night",
"start": "2027-02-01T00:00:00Z",
"end": "2027-02-02T08:00:00Z",
"requiredSkills": [
"Security guard"
]
}
]
}
}
Copy this example dataset into a file called sample.json to use in this hello world example.
|
2.1.1. Employees
In this example, there is one employee. employees includes id and skills.
{
"employees": [
{
"id": "Beth",
"skills": [
{
"id": "Security guard"
}
]
}
]
}
id is a unique identifier that identifies the employee.
In this case, the id has the value "Beth", but you could use the employee’s full name or an employee ID number.
skills is a unique identifier that represents the employee’s skills that are matched against the skills that are required for individual shifts.
In this case, skills has the value "Security guard" and could be any other role that is required for the shift, for instance, "Doctor", "Nurse", or "Receptionist".
There is no limit to the number of skills that can be listed.
It can be used to include certifications and licenses.
{
"id": "Beth",
"skills": [
{
"id": "Security guard"
},
{
"id": "CPR cert"
}
]
}
2.1.2. Shifts
In this example, there is one shift.
Shifts includes information about the shift, the start and end times, and the requiredSkills for the shift:
{
"shifts": [
{
"id": "Mon Night",
"start": "2027-02-01T00:00:00Z",
"end": "2027-02-02T08:00:00Z",
"requiredSkills": [
"Security guard"
]
}
]
}
id is a unique identifier that represents the shift to be worked, in this case "2027-02-01-night" represents a night shift on February 1st, 2027.
start is the start time of the shift.
end is the end time of the shift.
Both start and end uses the ISO 8601 date and time format.
requiredSkills contains the skills the employee must have to be assigned this shift. In this instance, the shift requires an employee with the skill Security guard.
2.2. Post the dataset
You have two options to post the dataset.
2.2.1. Post the dataset in the Timefold Platform UI
Typically, you post the dataset to the API. However, for testing purposes, you can upload your sample.json directly in the Timefold Platform UI.
-
Log into the Timefold Platform dashboard: https://app.timefold.ai
-
Select the Employee Shift Scheduling tile.
-
Click New run.
-
Select Custom and click Next
-
Upload the
sample.jsonfile you saved earlier. -
Click Schedule run.
-
Navigate to the Output section to see the completed schedule
2.2.2. Post the dataset to the Timefold OpenAPI
Learn how to configure an API Key to run the examples in this guide:
-
Log in to Timefold Platform: app.timefold.ai
-
From the Dashboard, click your tenant, and from the drop-down menu select Tenant Settings, then choose API Keys.
-
Create a new API key or use an existing one. Ensure the list of models for the API key contains the Employee Shift Scheduling model.
In the examples, replace <API_KEY> with the API Key you just copied.
Request the solution for your dataset by posting the sample.json file to the API endpoint /v1/schedules/.
curl -X POST -H "Content-type: application/json" -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules [email protected]
The dataset is validated. To learn more about the types of validation that are performed see the Validation guide.
2.3. Output from the request
The output to the API request follows:
{
"id": "ID",
"name": "NAME",
"submitDateTime": "2024-07-17T10:26:25.571295Z",
"startDateTime": null,
"activeDateTime": null,
"completeDateTime": null,
"shutdownDateTime": null,
"solverStatus": "SOLVING_SCHEDULED",
"score": null,
"tags": null,
"validationResult": null
}
The output includes an id and name that have been assigned to identify the run associated with the dataset.
You’ll use this id to retrieve the results.
Later, you’ll use name to locate more information in Timefold Platform.
solverStatus confirms the dataset has been scheduled for solving.
2.4. Request the solution
Append the ID from the output you received to the API endpoint /v1/schedules/ and create a GET request to retrieve the solution:
curl -X GET -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules/<ID>
2.5. Completed schedule
{
"run": {
"id": "ID",
"name": "NAME",
"submitDateTime": "2024-07-17T10:26:25.571295Z",
"startDateTime": "2024-07-17T10:26:30.719639034Z",
"activeDateTime": "2024-07-17T10:26:30.819639034Z",
"completeDateTime": "2024-07-17T10:26:33.991793212Z",
"shutdownDateTime": "2024-07-17T10:26:34.091793212Z",
"solverStatus": "SOLVING_COMPLETED",
"score": "0hard/0medium/0soft",
"tags": null,
"validationResult": {
"summary": "VALIDATION_NOT_SUPPORTED"
}
},
"modelOutput": {
"shifts": [
{
"id": "Mon Night",
"employee": "Beth"
}
]
},
"kpis": {
"unassignedShifts": 0
}
}
The output shows the solverStatus is SOLVING COMPLETED.
modelOutput contains the solution for the dataset.
{
"modelOutput": {
"shifts": [
{
"id": "Mon Night",
"employee": "Beth"
}
]
}
}
shifts includes the shifts that have been scheduled and the employees assigned to the shifts.
Beyond hello world
This example walked you through creating a simple dataset to create a schedule for one employee for one shift. Timefold optimizes employee shift schedules for thousands of employees automatically with the goal of minimizing labor costs, ensuring proper coverage of employees with the correct skills, and increasing employee satisfaction through fairness of shift allocation and preferred shifts.
Configure a webhook
In this getting started guide, you learned how to retrieve the solution for your dataset through the API and Timefold Platform. However, you can configure a webhook to receive the solution without the need to poll the Timefold Platform API.
To configure a webhook:
-
Log in to Timefold Platform app.timefold.ai
-
From the Dashboard, click the tenant menu drop-down menu and select Tenant settings.
-
Select Webhook and click New webhook.
-
Give your webhook a name.
-
Enter the URL for your webhook and the header values.
-
Enable the webhook and click Add webhook.
See Configuring webhooks for more information.
Try the demo dataset
Timefold platform includes a demo dataset you can use to explore the functionality of the platform.
Access the demo dataset in the UI
To access the demo dataset in the UI:
-
Log into Timefold Platform: app.timefold.ai
-
Select the Employee Shift Scheduling tile.
-
Click New Run.
-
Select the demo dataset you would like to run from the drop-down menu, and click Schedule run.
Access the demo dataset with the API
To get the list of available demo datasets and information about each dataset from the API, make the following call:
curl -X GET -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/demo-data
To download the BASIC demo dataset, make the following API call:
curl -X GET -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/demo-data/BASIC -o sample.json
To post the demo dataset, use the following API call:
The output from the POST operation includes a run ID that you need for subsequent commands.
|
curl -X POST -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules [email protected]
To get the current status and score of the dataset, replace <ID> with the identifier from the previous post operation and make the following API call:
curl -X GET -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules/<ID>/metadata
To get the complete employee shift schedule, replace <ID> with the identifier from the previous post operation and make the following API call:
curl -X GET -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules/<ID>
Next
-
See the full API spec or try the online API.
-
Learn more about employee shift scheduling from our YouTube playlist.

