Create Customer
Create a new customer record for tracking payments and transactions.
POST
https://api.zenpayz.com/merchant/api/v1/customersBearer · API key
Request
Headers
| Header | Description |
|---|---|
Authorization REQUIRED | Bearer {api_key} |
X-Signature REQUIRED | HMAC-SHA256 signature |
X-Timestamp REQUIRED | ISO 8601 timestamp |
X-Secret-Salt REQUIRED | Secret salt for HMAC validation |
Content-Type REQUIRED | application/json |
Body Parameters
| Parameter | Type | Description |
|---|---|---|
email REQUIRED | string | Customer email address |
phone OPTIONAL | string | Phone number (10-15 characters) |
firstName OPTIONAL | string | Customer first name (1-100 characters) |
lastName OPTIONAL | string | Customer last name (1-100 characters) |
dateOfBirth OPTIONAL | string | Date of birth (YYYY-MM-DD) |
country REQUIRED | string | ISO country code |
ipAddress REQUIRED | string | Customer IPv4 address |
deviceFingerprint OPTIONAL | string | Device fingerprint for fraud detection (10-255 characters) |
userAgent OPTIONAL | string | Browser user agent string (1-500 characters) |
metadata OPTIONAL | object | Custom key-value pairs |
Response
Success (201 Created)
{
"success": true,
"data": {
"customerId": "cust_a1b2c3d4e5f6g7h8",
"email": "john@example.com",
"phone": "+1234567890",
"firstName": "John",
"lastName": "Doe",
"country": "US",
"status": "active",
"riskLevel": "low",
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z"
},
"message": "Customer created successfully",
"error": null,
"meta": {
"request_id": "req_xxxxx",
"timestamp": "2024-01-15T10:30:00.000Z",
"processing_time_ms": 120,
"api_version": "v1",
"endpoint": "POST /customers",
"user_type": "merchant"
}
}
Error Responses
| Code | HTTP | Message |
|---|---|---|
| VALIDATION_ERROR | 400 | Invalid request parameters |
| UNAUTHORIZED | 401 | Invalid API key |
| DUPLICATE_CUSTOMER | 409 | Customer with email already exists |
Examples
- cURL
- JavaScript
- SDK
curl -X POST https://api.zenpayz.com/merchant/api/v1/customers \
-H "Authorization: Bearer zp_test_xxxxx" \
-H "X-Timestamp: 2024-01-15T10:30:00.000Z" \
-H "X-Signature: a1b2c3d4e5f6..." \
-H "X-Secret-Salt: your_secret_salt" \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"firstName": "John",
"lastName": "Doe",
"phone": "+1234567890",
"country": "US",
"ipAddress": "203.0.113.42"
}'
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/customers', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Timestamp': timestamp,
'X-Signature': signature,
'X-Secret-Salt': secretSalt,
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'john@example.com',
firstName: 'John',
lastName: 'Doe',
phone: '+1234567890',
country: 'US',
ipAddress: '203.0.113.42',
}),
});
const result = await response.json();
console.log(result.data.customerId); // cust_a1b2c3d4e5f6g7h8
const customer = await zenpays.customers.create({
email: 'john@example.com',
firstName: 'John',
lastName: 'Doe',
phone: '+1234567890',
country: 'US',
ipAddress: '203.0.113.42',
});
console.log(customer.customerId); // cust_a1b2c3d4e5f6g7h8