In this tutorial, you learn how to find a shift and update properties with the PATCH
METHOD. The use case is very practical - a store manager creates a new shift by locating an old one with a CLOSED status and then changing the shift date and status (from CLOSED to OPEN). Knowing how to update a shift helps store managers save time. They can quickly generate a new shift from a previous record and avoid creating a new shift from scratch.
Expect this tutorial to take about 15 minutes to complete.
Make sure you’ve completed the Before you start checklist on the development system you’ll use for the tutorial.
The first step is to display a list of shifts with the CLOSED status, find the record that needs to be updated, and note the ID number. Viewing a specific shift record requires the GET
method.
{server_url}/shifts?status=closed
Content-Type: application/json
Sample call.
curl --location 'http://localhost:3000/shifts?status=closed'
In the Postman app, select Send to make the request. The service returns a JSON object that contains all closed shifts. Each shift has the following format. Note the id
of the shift to update.
[
{
"id": "03b6",
"date": "2024-07-13",
"start_time": "0900",
"shift_length": "6",
"warning": "opening",
"location_detail": "Eatons Centre",
"status": "closed"
},
{
"id": "03d3",
"date": "2024-06-11",
"start_time": "0900",
"shift_length": "6",
"warning": "opening",
"location_detail": "Eatons Centre",
"status": "closed"
},
{
"id": "81a2",
"date": "2024-06-11",
"start_time": "0900",
"shift_length": "6",
"warning": "opening",
"location_detail": "Eatons Centre",
"status": "closed"
}
]
Now that you know the shift id
, send a PATCH request to the /shifts/{id} endpoint to update the record.
To update shift properties:
In Postman, create a new request with these values:
{server_url}/shifts/{id}
Content-Type: application/json
Sample call for shift ID 03b6.
curl --location --request PATCH 'http://localhost:3000/shifts/03b6' \
--header 'Content-Type: application/json' \
--data ' {
"date": "2024-07-22",
"status": "open"
}'
In the Request Body, add the properties and parameters that require an update. In this example, the date changes to July 22, and the status changes from CLOSED
to OPEN
.
{
"date": "2024-07-22",
"status": "open"
}
Click Send. The service updates the shift record and returns a 200 OK along with the updated task as a JSON object.
{
"id": "03b6",
"date": "2024-07-22",
"start_time": "0900",
"shift_length": "6",
"warning": "opening",
"location_detail": "Eatons Centre",
"status": "open"
}
Now that you have verified this API workflow in Postman, you’re ready to integrate it into your application. For more information, contact your customer success manager or read our Quickstart guide