Create and store customer records tied to their merchant accounts.
Create Customer
As a developer, create a customer record tied to your merchant account with POST /customer, then save the returned id for future calls from your API integration. This ID is a universally unique identifier (UUID); use it as the customer_id when another endpoint requests a customer ID.
Key Features
Store customer details such as name, email, and company information
Returns a unique customer UUID in id for use in subsequent API calls
Supports ISO 3 code for address_country, sent to processing gateway when provided
Add customer-specific custom fields to capture additional data unique to your business
Data Validation
Requires at least one of the following fields to create a record: firstname, lastname, email, or company.
Create a customer and save the ID
Prerequisites
- Install Python 3 to run the example using its standard library; no additional packages are required.
- Obtain your merchant API key and keep it private. Enter it at the hidden prompt when you run the example rather than saving it in your code.
Send the request
- Save the following code as
create_customer.py. The request sends onlyemail, which satisfies the requirement to supply at least one customer identity field. Replace the sample email with your customer's email before running it. - Run
python3 create_customer.pyand enter your merchant API key. Each successful request creates a new record, even if a customer already has the same email; avoid rerunning it unless you intend to create another customer.
import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
def main():
api_key = getpass.getpass("Merchant API key: ").strip()
if not api_key:
print("No API key entered. No request was sent.", file=sys.stderr)
return 1
request = Request(
"https://apiprod.fattlabs.com/customer",
data=json.dumps({"email": "[email protected]"}).encode("utf-8"),
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
"Accept": "application/json",
},
method="POST",
)
try:
with urlopen(request, timeout=30) as response:
status = response.getcode()
body = response.read().decode("utf-8")
except HTTPError as error:
print(f"HTTP {error.code}: {error.read().decode('utf-8', errors='replace')}",
file=sys.stderr)
if error.code == 422:
print("Supply firstname, lastname, email, or company; check field limits.",
file=sys.stderr)
elif error.code == 401:
print("Check that your merchant API key is valid.", file=sys.stderr)
return 1
except (URLError, TimeoutError, OSError) as error:
print(f"Connection failed: {error}", file=sys.stderr)
print("Check whether the customer was created before retrying to avoid duplicates.",
file=sys.stderr)
return 1
try:
customer = json.loads(body)
except (ValueError, UnicodeError):
print(f"HTTP {status}: expected a JSON customer record. Check before retrying.",
file=sys.stderr)
return 1
# Find existing IDs in Stax Pay > Customers > select a customer to open the drawer.
# For this new record, capture the API's returned ID instead of copying a dummy ID.
customer_id = customer.get("id") if isinstance(customer, dict) else None
if status != 200 or not isinstance(customer_id, str) or not customer_id:
print(f"Unexpected response (HTTP {status}): {body}", file=sys.stderr)
print("Check whether the customer was created before retrying.", file=sys.stderr)
return 1
print(json.dumps({"status": status, "customer_id": customer_id}, indent=2))
return 0
if __name__ == "__main__":
sys.exit(main())- Save the returned ID in your application for subsequent customer-related API calls. A successful run prints the following summary; your generated UUID will differ:
{
"status": 200,
"customer_id": "59327746-fbca-4fb6-adf0-e88c99245548"
}The script labels the captured value customer_id; the API response field is id. Use the actual returned UUID, not the sample value. The code comment identifies where you can find an existing customer's ID in Stax Pay for reference; the script captures the new customer's ID directly from the API response.
Required and optional fields
Required Fields
At least one of the following fields must be provided to successfully create a customer record:
firstname(string): Customer's first namelastname(string): Customer's last nameemail(string): Customer's email addresscompany(string): Company name associated with the customer
Optional Fields
address_country(string): The ISO 3 code for the customer's country. This will be sent to the processing gateway if provided. Example:USAfor the United Statesoptions(object): Additional configuration options including custom fields specific to your customer record
Custom Fields with Options Parameter
The options parameter allows you to add custom fields that are specific to your customer record. These custom fields can capture additional customer information that's unique to your business requirements.
Important Notes:
- Custom field values are always stored as strings regardless of the specified type
- The type field indicates how the value should be interpreted and validated
- Custom fields are unique to your customer record and don't affect other customer records
Response Structure
| Code | Response | Description |
|---|---|---|
| 200 | Success | Customer created. Returns the customer UUID in id and customer data. |
| 422 | Validation Error | Missing or invalid fields. Supply at least one of firstname, lastname, email, or company; each has a maximum length of 255 characters. |
| 401 | Unauthorized | API key invalid or missing. |
| 500 | Internal Server Error | An unexpected error occurred. |
Important Considerations
Field Validation: Ensure at least one required field (firstname, lastname, email, company) is present in the payload.
Duplicate Customers: Creating a customer with duplicate details (e.g., email) generates a new customer record with a unique id. It does not merge existing records.
Country Code Format: If using address_country, confirm it matches the ISO 3 standard to avoid validation errors.
Future Transactions: Use the returned id as the customer_id when associating payment methods, transactions, or invoices with this customer.
Use meaningful and unique data for customer identification (e.g., email or company)
Keep customer information updated by utilizing the Update a Customer endpoint
Keep your merchant API key private. Follow Payment Card Industry Data Security Standard (PCI DSS) practices to support your compliance efforts; this endpoint does not establish compliance. Consult your compliance or legal team regarding specific requirements.
