| Previous Topic | Next Topic |
|---|---|
| Online Ordering Module 3b: Show Account Balance | Online Ordering Module 5: Redemptions |
Online Ordering API Certification Tutorial - Module 4: Update User Profile
Goal
Update the values of fields in the profile of a loyalty guest user in the online ordering system of a business via the website or mobile app.
Prerequisites
You must have read the Online Ordering Module 1a: Create User tutorial.
Use Cases and Context
You can use the Update User Information API to update the values of profile fields for a user. You cannot update profile fields during sign-up; the update user call must be made after sign-up (i.e., after the user has been created).
Applicable API Endpoints
| Endpoint Name/Path | Relevant Request Parameters | Relevant Response Parameters |
| Update User Information PUT {server-name}/api/auth/users |
client access_token Applicable parameters shown under the User object (e.g., city, state, zip_code, etc.) |
Applicable parameters that were provided with the request under the User object (e.g., city, state, zip_code, etc.) |
Example Code
curl --location --request PUT 'https://SERVER_NAME_GOES_HERE.punchh.com/api/auth/users' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-pch-digest: SIGNATURE_GOES_HERE' \
--header 'Authorization: Bearer ACCESS_TOKEN_GOES_HERE' \
--header 'User-Agent: Punchh/OnlineOrder/1.0/Web/BrowserVersion/OS_Type' \
--data-raw '{
"client": "CLIENT_GOES_HERE",
"user": {
"city": "Austin",
"state": "TX",
"zip_code": "98701"
}
}'
import json
from http_client import send_request
def update_user_information():
path = "/api/auth/users"
http_verb = "PUT"
body = json.dumps({
"client": "CLIENT_GOES_HERE",
"user": {
"city": "Austin",
"state": "TX",
"zip_code": "98701"
}
})
response = send_request(path, http_verb, body)
print(f"Response: {response}")
update_user_information()
class UpdateUserInformation
require_relative 'generate_signature.rb'
require_relative 'http_client.rb'
require 'json'
# Client for the environment that you are pointing the request to
CLIENT = "CLIENT_GOES_HERE"
PATH = "/api/auth/users"
HTTP_VERB = "PUT"
def self.update_user_information
body = {client: CLIENT, user: {
city: "Austin",
state: "TX",
zip_code: "98701"
}}.to_json
response = HttpClient::send_request(PATH, HTTP_VERB, body)
end
end
UpdateUserInformation.update_user_information
Workflow
One or more parameters may be sent with the User object in the request of the Update User Information API. This API endpoint is a PUT that effectively works like a PATCH, so you can send granular updates in the API request without having to replace the entire User object.
Following are examples of user profile fields and the corresponding parameters that can be used to update the values of those fields:
- Street address (
address_line1) - Phone number (
phone) - Birthday (
birthday) - City (
city) - State (
state) - Email address (
email) - Zip code (
zip_code) - Favorite locations (
favourite_locations) - First name (
first_name) - Last name (
last_name)
Notes
- Some user profile fields may be read-only, and some fields may be updated only by Punchh.
- Birthday can be updated only one time using this endpoint if a guest's birthday was not already set at sign-up. If the
birthdayparameter is sent either after sign-up where birthday was already sent, or after birthday was already updated via this endpoint, the API will not return an error and instead will not update the birthday parameter and return a 200 OK response. This is to prevent guests from changing their birthday to avail themselves of birthday rewards multiple times per year.
Best Practices
- When a user initially creates a loyalty guest account with a business, several user profile fields may or may not be required depending on how the business is configured in the Punchh platform. If a mandatory field is enabled after the account has already been created, that can cause issues for an existing user. Depending on the mandatory field, it can cause the existing user to not be able to log in until the account is updated to include the required field. For details, see Online Ordering Module 1a: Create User.
- The User object in the Sign up With Email and Password API is not the same as the User object in the Update User Information API. A user must first be created in the system via the Sign up With Email and Password API. After the user is created, the Update User Information API can be used to update the values of profile fields for the user.