Modify an existing customer record in your merchant account.
Update an existing customer record in your merchant account with PUT /customer/{id}.
Use this API reference if you are a developer integrating customer updates into your application. Keeping customer data accurate supports your compliance efforts; consult your legal team regarding specific requirements.
Key Features
- Modify Existing Records: Update any field in the customer record, such as name, email, address, or phone number.
- Partial Updates: Supply only the fields you want to modify, including at least one of
firstname,lastname,email, orcompany. Omit fields you want to leave unchanged rather than sending blank values. - Correct Errors: Fix inaccurate or outdated data in the initial customer record.
Update a customer's email
Prerequisites
- Install Python 3 to run the example without third-party packages.
- Select your sandbox (a test environment) in the Stax Pay merchant switcher, then copy your secret API key from Stax Pay > Apps > API Keys. Use a key for the merchant account that owns the customer, and keep it out of client-side code and public repositories.
- Open Stax Pay > Customers, then click a customer to view their information and customer ID. You can also copy the customer's
idfrom the Find all Customer response. An ID looks liked45ee88c-8b27-4be8-8d81-77dda1b81826; this example value is not a customer you can update.
Send and verify the update
- Retrieve the existing record with Get a Customer's Information to confirm you have the right customer before changing their data.
- Save the following code as
update_customer.py, then runpython3 update_customer.py. Enter your sandbox key, the existing customer's ID, and the new email address at the prompts. The example sends onlyemail, which meets the requirement to supply at least one offirstname,lastname,email, orcompany.
import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.parse import quote
from urllib.request import Request, urlopen
def main():
# Copy the sandbox key from Stax Pay > Apps > API Keys.
api_key = getpass.getpass("Stax secret API key: ").strip()
# Open Stax Pay > Customers, then click the customer to find their ID.
customer_id = input("Existing customer ID: ").strip()
email = input("New customer email: ").strip()
if not api_key or not customer_id or not email:
sys.exit("API key, customer ID, and email must not be empty.")
request = Request(
"https://apiprod.fattlabs.com/customer/" + quote(customer_id, safe=""),
data=json.dumps({"email": email}).encode("utf-8"),
headers={
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
"Accept": "application/json",
},
method="PUT",
)
try:
# Use a timeout so a stalled connection does not wait indefinitely.
with urlopen(request, timeout=30) as response:
status = response.status
body = response.read().decode("utf-8")
except HTTPError as error:
print("HTTP", error.code, file=sys.stderr)
print(error.read().decode("utf-8", errors="replace"), file=sys.stderr)
sys.exit("Update failed. Use the response guidance below to investigate.")
except (URLError, TimeoutError, OSError) as error:
sys.exit(f"Connection failed: {error}. Retrieve the customer before retrying to check whether the update took effect.")
if status != 200:
sys.exit(f"Unexpected HTTP status {status}. Retrieve the customer to verify the result.")
try:
customer = json.loads(body)
except ValueError:
sys.exit("The response was empty or invalid JSON. Retrieve the customer to verify the result.")
if not isinstance(customer, dict):
sys.exit("Unexpected response format. Retrieve the customer to verify the result.")
if customer.get("id") != customer_id or customer.get("email") != email:
sys.exit("The response did not confirm the requested update. Retrieve the customer to inspect the current values.")
print("HTTP 200: Customer email updated.")
print(json.dumps({"id": customer["id"], "email": customer["email"]}, indent=2))
if __name__ == "__main__":
try:
main()
except (EOFError, KeyboardInterrupt):
sys.exit("\nInput cancelled; no further requests will be sent.")- Confirm that the request returns HTTP
200and the response contains the customer's ID and new email. For the example ID above and an email of[email protected], the script prints:
HTTP 200: Customer email updated.
{
"id": "d45ee88c-8b27-4be8-8d81-77dda1b81826",
"email": "[email protected]"
}Optional: Update other customer fields
Include only fields you want to change, and supply at least one of firstname, lastname, email, or company. Do not rely on blank values to preserve existing data.
| Parameter | Type | Constraints | Default |
|---|---|---|---|
id (path) | string | Required; use an existing customer's ID | None; you must supply it |
firstname | string | Maximum 255 characters; required if lastname, email, and company are absent | No documented default |
lastname | string | Maximum 255 characters; required if firstname, email, and company are absent | No documented default |
email | string | Valid email address; maximum 255 characters; required if firstname, lastname, and company are absent | No documented default |
company | string | Maximum 255 characters; required if firstname, lastname, and email are absent | No documented default |
address_country | string | ISO 3-letter country code, such as USA; maximum 3 characters | No documented default |
Response Structure
| Code | Response | Description |
|---|---|---|
| 200 | Success | The customer record was successfully updated. |
| 400 | Bad Request | Invalid or missing fields in the request. |
| 401 | Unauthorized | API key invalid or missing. |
| 404 | Not Found | No customer found with the provided id. Check the ID and the merchant account associated with your key. |
| 422 | Validation Error | Review the returned field errors. Supply at least one of firstname, lastname, email, or company, and check field formats and lengths. |
| 500 | Internal Server Error | An unexpected error occurred on the server. Retrieve the customer to check whether the update took effect before retrying. |
Important Considerations
Required Access: The API key must belong to the merchant associated with the customer record.
Immutable Fields: Use the customer's id in the request path to select the record; do not attempt to change it in the request body.
Deleted Records: Updates cannot be made to soft-deleted customer records. Use the Find all Customer endpoint to confirm the deleted_at status.
Validation: Ensure all supplied fields follow the required formats. For example:
address_country: Must be a valid ISO 3-letter code.email: Should be a properly formatted email address.
Best Practices
- Retrieve the existing record with the Get a Customer's Information endpoint before updating to avoid overwriting fields unnecessarily.
- Log updates for auditing and troubleshooting purposes.
- Use this endpoint to maintain accurate customer data, which is critical for reporting and transactional accuracy.
