Update Customer Information

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, or company. 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

  1. Install Python 3 to run the example without third-party packages.
  2. 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.
  3. Open Stax Pay > Customers, then click a customer to view their information and customer ID. You can also copy the customer's id from the Find all Customer response. An ID looks like d45ee88c-8b27-4be8-8d81-77dda1b81826; this example value is not a customer you can update.

Send and verify the update

  1. Retrieve the existing record with Get a Customer's Information to confirm you have the right customer before changing their data.
  2. Save the following code as update_customer.py, then run python3 update_customer.py. Enter your sandbox key, the existing customer's ID, and the new email address at the prompts. The example sends only email, which meets the requirement to supply at least one of firstname, lastname, email, or company.
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.")
  1. Confirm that the request returns HTTP 200 and 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.

ParameterTypeConstraintsDefault
id (path)stringRequired; use an existing customer's IDNone; you must supply it
firstnamestringMaximum 255 characters; required if lastname, email, and company are absentNo documented default
lastnamestringMaximum 255 characters; required if firstname, email, and company are absentNo documented default
emailstringValid email address; maximum 255 characters; required if firstname, lastname, and company are absentNo documented default
companystringMaximum 255 characters; required if firstname, lastname, and email are absentNo documented default
address_countrystringISO 3-letter country code, such as USA; maximum 3 charactersNo documented default

Response Structure

CodeResponseDescription
200SuccessThe customer record was successfully updated.
400Bad RequestInvalid or missing fields in the request.
401UnauthorizedAPI key invalid or missing.
404Not FoundNo customer found with the provided id. Check the ID and the merchant account associated with your key.
422Validation ErrorReview the returned field errors. Supply at least one of firstname, lastname, email, or company, and check field formats and lengths.
500Internal Server ErrorAn 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.
Path Params
string
required
Body Params
string

Max: 255. Required if no lastname, email, company supplied

string

Max: 255. Required if no firstname, email, company supplied

string

Max: 255. Required if no firstname, lastname, company supplied

string

Max: 255. Required if no firstname, lastname, email supplied

string

Matching regex: /[0-9]{10,15}/

string

Max: 255

string

Max: 255

string

Max: 255

string

Max: 2

string

Max: 16

string

Max: 3

string

For internal notes only; not visible to customers in invoices or communications. Max: 21844

string

This field is for the merchant's internal use. Max: 255.

files
array of strings

Array of strings(50) where each index is a valid file_id

files
cc_emails
array of strings

Array of strings(255) where each index is a valid email address

cc_emails
cc_sms
array of strings

Array of strings(255) where each index is a valid phone number

cc_sms
boolean
options
object

Additional customer options such as custom fields

Responses

Language
Credentials
Bearer
JWT
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json