Tutorial: Update a user’s pain level
In this tutorial, you’ll learn how to update a user’s pain level using the PATCH method to change
a specific field in the user resource. Whether a user’s pain increases or decreases, keeping this
information current helps them track and change their recovery approach, if necessary.
Expect this tutorial to take about 10 minutes to complete.
Before you start
Make sure you’ve completed the Getting Started guide on the development system you’ll use for the tutorial.
Update a user’s pain level
Updating a user’s pain level requires using the PATCH method to change the user
resource in the service. The PATCH method allows you to update specific fields without sending the
entire user object.
This example updates the pain level for a user from 7 to 4.
-
Make sure your local service is running, or start it by using this command in the terminal:
cd <your-github-workspace>/SciaticaSisters-API/api json-server -w sciatica-sisters-db-source.json
Postman request
- Open Postman and create a new request:
- Click New > HTTP or the + icon in the header.
- Set the request method to
PATCHusing the corresponding dropdown menu. -
In the request URL field, enter:
{base_url}/users/1
- Set up the request headers:
- Click the Headers tab below the URL field.
- Add a header:
- Key:
Content-Type - Value:
application/json
- Key:
- Set up the request body:
- Click the Body tab below the URL field.
- Select raw from the radio button options.
- Select JSON from the dropdown menu on the right.
-
In the text area, enter:
{ "painLevel": 4 }
-
Click Send to make the request.
-
The system returns the complete updated user object with the new pain level. Note that only the
painLevelfield changed, while all other fields remained the same.{ "id": 1, "firstName": "Sarah", "lastName": "Johnson", "email": "s.johnson@example.com", "age": 42, "painLocation": "lower-back-left", "painLevel": 4, "diagnosisDate": "2024-03-15" }
cURL request
-
Open your terminal and run this command:
curl -X PATCH {base_url}/users/1 \ -H "Content-Type: application/json" \ -d '{"painLevel": 4}' -
The system returns the complete updated user object with the new pain level. Note that only the
painLevelfield changed, while all other fields remained the same.{ "id": 1, "firstName": "Sarah", "lastName": "Johnson", "email": "s.johnson@example.com", "age": 42, "painLocation": "lower-back-left", "painLevel": 4, "diagnosisDate": "2024-03-15" }
Check your results
Postman verification
- Create a new request in Postman.
- Set the request method to
GET. -
In the request URL field, enter:
{base_url}/users/1 -
Click Send.
- You should see that the
painLevelis now 4 instead of the original value of 7. All other user information remains unchanged.
cURL verification
-
Run this command:
curl -X GET {base_url}/users/1 -
You should see that the
painLevelis now 4 instead of the original value of 7. All other user information remains unchanged.
Common errors and troubleshooting
Pain level not updating
If the pain level doesn’t change, verify you’re using the correct field name painLevel in camelCase.
Using pain_level, PainLevel, or other variations won’t work.
Invalid pain level value
The pain level must be a number between 1 and 10. Values outside this range or non-numeric values may cause errors or unexpected behavior.
404 not found error
If you receive this error, the user ID in your request URL doesn’t exist. Verify the correct user ID
by calling GET on /users first to see all available users.
What you learned
After completing this tutorial, you now know how to update a specific field in a user resource using
the PATCH method with Postman or cURL. This is useful when a user reports changes to their pain level
without needing to update their entire profile. You’re now able to accurately track user progress.
Next steps
- Log your first activity to start tracking exercises.
- Compare exercises to see which activities are effective.
- Create a user profile to add a patient.
Related topics
Security note
In a production environment, this operation would require proper authentication to ensure only authorized users can change patient data. See Authentication for details.