curl -X POST https://api.stateset.com/api/v1/customers \
-H "Authorization: Bearer ${STATESET_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"email": "john.doe@example.com",
"first_name": "John",
"last_name": "Doe",
"phone": "+1-555-123-4567"
}'
curl -X POST https://api.stateset.com/api/v1/customers \
-H "Authorization: Bearer ${STATESET_API_KEY}" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: customer-creation-12345" \
-d '{
"email": "sarah.wilson@techcorp.com",
"first_name": "Sarah",
"last_name": "Wilson",
"phone": "+1-555-987-6543",
"date_of_birth": "1985-12-03",
"address": {
"street1": "123 Innovation Drive",
"street2": "Suite 200",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105",
"country": "US"
},
"marketing_consent": true,
"customer_tier": "gold",
"referral_source": "paid_search",
"notes": "High-value enterprise customer",
"tags": ["enterprise", "tech", "high-value"],
"custom_fields": {
"company_name": "Tech Corp",
"job_title": "CTO",
"industry": "Technology"
},
"preferences": {
"email_notifications": true,
"sms_notifications": false,
"language": "en",
"timezone": "America/Los_Angeles"
}
}'
import { StateSetClient } from 'stateset-node';
const client = new StateSetClient({
apiKey: process.env.STATESET_API_KEY
});
try {
const customer = await client.customers.create({
email: 'john.doe@example.com',
first_name: 'John',
last_name: 'Doe',
phone: '+1-555-123-4567',
address: {
street1: '123 Main Street',
city: 'New York',
state: 'NY',
postal_code: '10001',
country: 'US'
},
marketing_consent: true,
customer_tier: 'silver',
tags: ['newsletter-subscriber']
});
console.log('Customer created:', customer.id);
// Optionally, create a welcome email workflow
await client.workflows.trigger({
workflow_id: 'welcome_series',
customer_id: customer.id
});
} catch (error) {
if (error.code === 'DUPLICATE_EMAIL') {
console.log('Customer already exists with this email');
} else {
console.error('Error creating customer:', error.message);
}
}
from stateset import StateSet
import os
client = StateSet(api_key=os.getenv('STATESET_API_KEY'))
try:
customer = client.customers.create({
'email': 'jane.smith@example.com',
'first_name': 'Jane',
'last_name': 'Smith',
'phone': '+1-555-234-5678',
'address': {
'street1': '456 Oak Avenue',
'city': 'Los Angeles',
'state': 'CA',
'postal_code': '90210',
'country': 'US'
},
'marketing_consent': False,
'customer_tier': 'bronze',
'referral_source': 'social_media',
'custom_fields': {
'how_did_you_hear': 'Instagram ad',
'interests': 'sustainability'
}
})
print(f'Customer created: {customer.id}')
# Send welcome email
client.emails.send({
'template': 'welcome',
'to': customer.email,
'variables': {
'first_name': customer.first_name
}
})
except Exception as error:
if hasattr(error, 'code') and error.code == 'DUPLICATE_EMAIL':
print('Customer already exists')
else:
print(f'Error: {str(error)}')
require 'stateset'
client = StateSet::Client.new(
api_key: ENV['STATESET_API_KEY']
)
begin
customer = client.customers.create({
email: 'mike.johnson@example.com',
first_name: 'Mike',
last_name: 'Johnson',
phone: '+1-555-345-6789',
address: {
street1: '789 Pine Street',
city: 'Seattle',
state: 'WA',
postal_code: '98101',
country: 'US'
},
customer_tier: 'platinum',
tags: ['vip', 'longtime-customer']
})
puts "Customer created: #{customer.id}"
rescue StateSet::DuplicateEmailError
puts "Customer already exists with this email"
rescue StateSet::Error => e
puts "Error creating customer: #{e.message}"
end
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/stateset/stateset-go"
"github.com/stateset/stateset-go/option"
)
func main() {
client := stateset.NewClient(
option.WithAPIKey(os.Getenv("STATESET_API_KEY")),
)
customer, err := client.Customers.Create(context.Background(), &stateset.CustomerCreateParams{
Email: "alex.brown@example.com",
FirstName: "Alex",
LastName: "Brown",
Phone: "+1-555-456-7890",
Address: &stateset.AddressParams{
Street1: "321 Elm Street",
City: "Austin",
State: "TX",
PostalCode: "73301",
Country: "US",
},
MarketingConsent: stateset.Bool(true),
CustomerTier: stateset.String("gold"),
Tags: []string{"referral", "premium"},
})
if err != nil {
var apiErr *stateset.Error
if errors.As(err, &apiErr) && apiErr.Code == "DUPLICATE_EMAIL" {
fmt.Println("Customer already exists")
return
}
log.Fatal(err)
}
fmt.Printf("Customer created: %s\n", customer.ID)
}
<?php
require_once 'vendor/autoload.php';
use StateSet\StateSetClient;
use StateSet\Exception\StateSetException;
$client = new StateSetClient([
'api_key' => $_ENV['STATESET_API_KEY']
]);
try {
$customer = $client->customers->create([
'email' => 'lisa.davis@example.com',
'first_name' => 'Lisa',
'last_name' => 'Davis',
'phone' => '+1-555-567-8901',
'address' => [
'street1' => '654 Maple Drive',
'city' => 'Denver',
'state' => 'CO',
'postal_code' => '80202',
'country' => 'US'
],
'customer_tier' => 'silver',
'marketing_consent' => true,
'referral_source' => 'email'
]);
echo "Customer created: " . $customer->id . "\n";
// Send welcome SMS if phone provided
if ($customer->phone) {
$client->sms->send([
'to' => $customer->phone,
'message' => "Welcome to our store, {$customer->first_name}!"
]);
}
} catch (StateSetException $e) {
if ($e->getCode() === 'DUPLICATE_EMAIL') {
echo "Customer already exists\n";
} else {
echo "Error: " . $e->getMessage() . "\n";
}
}
?>
import com.stateset.StateSetClient;
import com.stateset.models.Customer;
import com.stateset.models.CustomerCreateParams;
import com.stateset.models.Address;
import com.stateset.exception.StateSetException;
public class CreateCustomerExample {
public static void main(String[] args) {
StateSetClient client = StateSetClient.builder()
.apiKey(System.getenv("STATESET_API_KEY"))
.build();
try {
CustomerCreateParams params = CustomerCreateParams.builder()
.email("tom.wilson@example.com")
.firstName("Tom")
.lastName("Wilson")
.phone("+1-555-678-9012")
.address(Address.builder()
.street1("987 Oak Boulevard")
.city("Miami")
.state("FL")
.postalCode("33101")
.country("US")
.build())
.customerTier("gold")
.marketingConsent(true)
.addTag("newsletter")
.addTag("loyalty-program")
.build();
Customer customer = client.customers().create(params);
System.out.println("Customer created: " + customer.getId());
} catch (StateSetException e) {
if ("DUPLICATE_EMAIL".equals(e.getCode())) {
System.out.println("Customer already exists");
} else {
System.err.println("Error: " + e.getMessage());
}
}
}
}
mutation CreateCustomer($input: CustomerCreateInput!) {
createCustomer(input: $input) {
id
email
firstName
lastName
fullName
phone
address {
street1
street2
city
state
postalCode
country
}
customerTier
marketingConsent
status
createdAt
stripeCustomerId
tags
customFields
preferences {
emailNotifications
smsNotifications
language
timezone
}
}
}
# Variables:
{
"input": {
"email": "emily.chen@example.com",
"firstName": "Emily",
"lastName": "Chen",
"phone": "+1-555-789-0123",
"address": {
"street1": "159 Innovation Way",
"city": "Boston",
"state": "MA",
"postalCode": "02101",
"country": "US"
},
"customerTier": "platinum",
"marketingConsent": true,
"tags": ["enterprise", "tech-executive"],
"customFields": {
"company": "Innovation Labs",
"role": "VP Engineering"
}
}
}
{
"id": "cust_1NXWPnCo6bFb1KQto6C8OWvE",
"email": "sarah.wilson@techcorp.com",
"first_name": "Sarah",
"last_name": "Wilson",
"full_name": "Sarah Wilson",
"phone": "+1-555-987-6543",
"date_of_birth": "1985-12-03",
"address": {
"street1": "123 Innovation Drive",
"street2": "Suite 200",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105",
"country": "US"
},
"customer_tier": "gold",
"marketing_consent": true,
"referral_source": "paid_search",
"stripe_customer_id": "cus_ABC123DEF456",
"status": "active",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"lifetime_value": 0.00,
"total_orders": 0,
"tags": ["enterprise", "tech", "high-value"],
"custom_fields": {
"company_name": "Tech Corp",
"job_title": "CTO",
"industry": "Technology"
},
"preferences": {
"email_notifications": true,
"sms_notifications": false,
"language": "en",
"timezone": "America/Los_Angeles"
}
}
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"errors": [
{
"field": "email",
"message": "Invalid email format",
"value": "invalid-email"
},
{
"field": "first_name",
"message": "First name is required",
"value": null
}
],
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
{
"error": {
"code": "DUPLICATE_EMAIL",
"message": "A customer with this email already exists",
"details": {
"email": "sarah.wilson@techcorp.com",
"existing_customer_id": "cust_2OYZRpEq8dHd3MSvq8E0QYwG"
},
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
{
"error": {
"code": "BUSINESS_RULE_VIOLATION",
"message": "Customer creation violates business rules",
"errors": [
{
"rule": "age_restriction",
"message": "Customer must be at least 13 years old",
"field": "date_of_birth"
}
],
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
Create Customer
Create a new customer record with comprehensive validation and optional integrations
POST
/
api
/
v1
/
customers
curl -X POST https://api.stateset.com/api/v1/customers \
-H "Authorization: Bearer ${STATESET_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"email": "john.doe@example.com",
"first_name": "John",
"last_name": "Doe",
"phone": "+1-555-123-4567"
}'
curl -X POST https://api.stateset.com/api/v1/customers \
-H "Authorization: Bearer ${STATESET_API_KEY}" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: customer-creation-12345" \
-d '{
"email": "sarah.wilson@techcorp.com",
"first_name": "Sarah",
"last_name": "Wilson",
"phone": "+1-555-987-6543",
"date_of_birth": "1985-12-03",
"address": {
"street1": "123 Innovation Drive",
"street2": "Suite 200",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105",
"country": "US"
},
"marketing_consent": true,
"customer_tier": "gold",
"referral_source": "paid_search",
"notes": "High-value enterprise customer",
"tags": ["enterprise", "tech", "high-value"],
"custom_fields": {
"company_name": "Tech Corp",
"job_title": "CTO",
"industry": "Technology"
},
"preferences": {
"email_notifications": true,
"sms_notifications": false,
"language": "en",
"timezone": "America/Los_Angeles"
}
}'
import { StateSetClient } from 'stateset-node';
const client = new StateSetClient({
apiKey: process.env.STATESET_API_KEY
});
try {
const customer = await client.customers.create({
email: 'john.doe@example.com',
first_name: 'John',
last_name: 'Doe',
phone: '+1-555-123-4567',
address: {
street1: '123 Main Street',
city: 'New York',
state: 'NY',
postal_code: '10001',
country: 'US'
},
marketing_consent: true,
customer_tier: 'silver',
tags: ['newsletter-subscriber']
});
console.log('Customer created:', customer.id);
// Optionally, create a welcome email workflow
await client.workflows.trigger({
workflow_id: 'welcome_series',
customer_id: customer.id
});
} catch (error) {
if (error.code === 'DUPLICATE_EMAIL') {
console.log('Customer already exists with this email');
} else {
console.error('Error creating customer:', error.message);
}
}
from stateset import StateSet
import os
client = StateSet(api_key=os.getenv('STATESET_API_KEY'))
try:
customer = client.customers.create({
'email': 'jane.smith@example.com',
'first_name': 'Jane',
'last_name': 'Smith',
'phone': '+1-555-234-5678',
'address': {
'street1': '456 Oak Avenue',
'city': 'Los Angeles',
'state': 'CA',
'postal_code': '90210',
'country': 'US'
},
'marketing_consent': False,
'customer_tier': 'bronze',
'referral_source': 'social_media',
'custom_fields': {
'how_did_you_hear': 'Instagram ad',
'interests': 'sustainability'
}
})
print(f'Customer created: {customer.id}')
# Send welcome email
client.emails.send({
'template': 'welcome',
'to': customer.email,
'variables': {
'first_name': customer.first_name
}
})
except Exception as error:
if hasattr(error, 'code') and error.code == 'DUPLICATE_EMAIL':
print('Customer already exists')
else:
print(f'Error: {str(error)}')
require 'stateset'
client = StateSet::Client.new(
api_key: ENV['STATESET_API_KEY']
)
begin
customer = client.customers.create({
email: 'mike.johnson@example.com',
first_name: 'Mike',
last_name: 'Johnson',
phone: '+1-555-345-6789',
address: {
street1: '789 Pine Street',
city: 'Seattle',
state: 'WA',
postal_code: '98101',
country: 'US'
},
customer_tier: 'platinum',
tags: ['vip', 'longtime-customer']
})
puts "Customer created: #{customer.id}"
rescue StateSet::DuplicateEmailError
puts "Customer already exists with this email"
rescue StateSet::Error => e
puts "Error creating customer: #{e.message}"
end
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/stateset/stateset-go"
"github.com/stateset/stateset-go/option"
)
func main() {
client := stateset.NewClient(
option.WithAPIKey(os.Getenv("STATESET_API_KEY")),
)
customer, err := client.Customers.Create(context.Background(), &stateset.CustomerCreateParams{
Email: "alex.brown@example.com",
FirstName: "Alex",
LastName: "Brown",
Phone: "+1-555-456-7890",
Address: &stateset.AddressParams{
Street1: "321 Elm Street",
City: "Austin",
State: "TX",
PostalCode: "73301",
Country: "US",
},
MarketingConsent: stateset.Bool(true),
CustomerTier: stateset.String("gold"),
Tags: []string{"referral", "premium"},
})
if err != nil {
var apiErr *stateset.Error
if errors.As(err, &apiErr) && apiErr.Code == "DUPLICATE_EMAIL" {
fmt.Println("Customer already exists")
return
}
log.Fatal(err)
}
fmt.Printf("Customer created: %s\n", customer.ID)
}
<?php
require_once 'vendor/autoload.php';
use StateSet\StateSetClient;
use StateSet\Exception\StateSetException;
$client = new StateSetClient([
'api_key' => $_ENV['STATESET_API_KEY']
]);
try {
$customer = $client->customers->create([
'email' => 'lisa.davis@example.com',
'first_name' => 'Lisa',
'last_name' => 'Davis',
'phone' => '+1-555-567-8901',
'address' => [
'street1' => '654 Maple Drive',
'city' => 'Denver',
'state' => 'CO',
'postal_code' => '80202',
'country' => 'US'
],
'customer_tier' => 'silver',
'marketing_consent' => true,
'referral_source' => 'email'
]);
echo "Customer created: " . $customer->id . "\n";
// Send welcome SMS if phone provided
if ($customer->phone) {
$client->sms->send([
'to' => $customer->phone,
'message' => "Welcome to our store, {$customer->first_name}!"
]);
}
} catch (StateSetException $e) {
if ($e->getCode() === 'DUPLICATE_EMAIL') {
echo "Customer already exists\n";
} else {
echo "Error: " . $e->getMessage() . "\n";
}
}
?>
import com.stateset.StateSetClient;
import com.stateset.models.Customer;
import com.stateset.models.CustomerCreateParams;
import com.stateset.models.Address;
import com.stateset.exception.StateSetException;
public class CreateCustomerExample {
public static void main(String[] args) {
StateSetClient client = StateSetClient.builder()
.apiKey(System.getenv("STATESET_API_KEY"))
.build();
try {
CustomerCreateParams params = CustomerCreateParams.builder()
.email("tom.wilson@example.com")
.firstName("Tom")
.lastName("Wilson")
.phone("+1-555-678-9012")
.address(Address.builder()
.street1("987 Oak Boulevard")
.city("Miami")
.state("FL")
.postalCode("33101")
.country("US")
.build())
.customerTier("gold")
.marketingConsent(true)
.addTag("newsletter")
.addTag("loyalty-program")
.build();
Customer customer = client.customers().create(params);
System.out.println("Customer created: " + customer.getId());
} catch (StateSetException e) {
if ("DUPLICATE_EMAIL".equals(e.getCode())) {
System.out.println("Customer already exists");
} else {
System.err.println("Error: " + e.getMessage());
}
}
}
}
mutation CreateCustomer($input: CustomerCreateInput!) {
createCustomer(input: $input) {
id
email
firstName
lastName
fullName
phone
address {
street1
street2
city
state
postalCode
country
}
customerTier
marketingConsent
status
createdAt
stripeCustomerId
tags
customFields
preferences {
emailNotifications
smsNotifications
language
timezone
}
}
}
# Variables:
{
"input": {
"email": "emily.chen@example.com",
"firstName": "Emily",
"lastName": "Chen",
"phone": "+1-555-789-0123",
"address": {
"street1": "159 Innovation Way",
"city": "Boston",
"state": "MA",
"postalCode": "02101",
"country": "US"
},
"customerTier": "platinum",
"marketingConsent": true,
"tags": ["enterprise", "tech-executive"],
"customFields": {
"company": "Innovation Labs",
"role": "VP Engineering"
}
}
}
{
"id": "cust_1NXWPnCo6bFb1KQto6C8OWvE",
"email": "sarah.wilson@techcorp.com",
"first_name": "Sarah",
"last_name": "Wilson",
"full_name": "Sarah Wilson",
"phone": "+1-555-987-6543",
"date_of_birth": "1985-12-03",
"address": {
"street1": "123 Innovation Drive",
"street2": "Suite 200",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105",
"country": "US"
},
"customer_tier": "gold",
"marketing_consent": true,
"referral_source": "paid_search",
"stripe_customer_id": "cus_ABC123DEF456",
"status": "active",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"lifetime_value": 0.00,
"total_orders": 0,
"tags": ["enterprise", "tech", "high-value"],
"custom_fields": {
"company_name": "Tech Corp",
"job_title": "CTO",
"industry": "Technology"
},
"preferences": {
"email_notifications": true,
"sms_notifications": false,
"language": "en",
"timezone": "America/Los_Angeles"
}
}
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"errors": [
{
"field": "email",
"message": "Invalid email format",
"value": "invalid-email"
},
{
"field": "first_name",
"message": "First name is required",
"value": null
}
],
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
{
"error": {
"code": "DUPLICATE_EMAIL",
"message": "A customer with this email already exists",
"details": {
"email": "sarah.wilson@techcorp.com",
"existing_customer_id": "cust_2OYZRpEq8dHd3MSvq8E0QYwG"
},
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
{
"error": {
"code": "BUSINESS_RULE_VIOLATION",
"message": "Customer creation violates business rules",
"errors": [
{
"rule": "age_restriction",
"message": "Customer must be at least 13 years old",
"field": "date_of_birth"
}
],
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
This endpoint creates a new customer and can optionally create associated accounts in integrated systems like Stripe.
Request Body
string
required
Customer’s email address. Must be unique and valid format.Example:
customer@example.comstring
required
Customer’s first name. Must be 1-50 characters.Example:
Johnstring
required
Customer’s last name. Must be 1-50 characters.Example:
Doestring
Customer’s phone number in E.164 format (recommended) or local format.Examples:
+1-555-123-4567, (555) 123-4567string
Customer’s date of birth in ISO 8601 format (YYYY-MM-DD).Example:
1990-05-15object
Customer’s primary address information.
Show Address Properties
Show Address Properties
boolean
default:"false"
Whether the customer has consented to marketing communications.
string
default:"bronze"
Customer tier for loyalty programs. Options:
bronze, silver, gold, platinumstring
How the customer found your business.Options:
organic, paid_search, social_media, referral, email, direct, otherstring
Existing Stripe customer ID if you’re syncing with an external Stripe account.Note: If not provided and Stripe integration is enabled, a new Stripe customer will be created automatically.
string
Internal notes about the customer (not visible to customer).Max length: 1000 characters
array
Array of tags for customer segmentation and organization.Example:
["vip", "wholesale", "early-adopter"]object
Additional custom fields as key-value pairs. Keys must be alphanumeric with underscores.Example:
{
"company_name": "Acme Corp",
"industry": "Technology",
"employee_count": "50-100"
}
object
Response
string
Unique identifier for the created customerExample:
cust_1NXWPnCo6bFb1KQto6C8OWvEstring
Customer’s email address
string
Customer’s first name
string
Customer’s last name
string
Customer’s full name (computed field)
string
Customer’s phone number
string
Customer’s date of birth
object
Customer’s address information
string
Customer’s loyalty tier
boolean
Marketing consent status
string
Associated Stripe customer ID (if Stripe integration is enabled)
string
ISO 8601 timestamp when the customer was created
string
ISO 8601 timestamp when the customer was last updated
string
Customer status:
active, inactive, suspendednumber
Customer’s lifetime value (computed from order history)
integer
Total number of orders placed by this customer
array
Array of customer tags
object
Custom field key-value pairs
object
Customer communication preferences
curl -X POST https://api.stateset.com/api/v1/customers \
-H "Authorization: Bearer ${STATESET_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"email": "john.doe@example.com",
"first_name": "John",
"last_name": "Doe",
"phone": "+1-555-123-4567"
}'
curl -X POST https://api.stateset.com/api/v1/customers \
-H "Authorization: Bearer ${STATESET_API_KEY}" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: customer-creation-12345" \
-d '{
"email": "sarah.wilson@techcorp.com",
"first_name": "Sarah",
"last_name": "Wilson",
"phone": "+1-555-987-6543",
"date_of_birth": "1985-12-03",
"address": {
"street1": "123 Innovation Drive",
"street2": "Suite 200",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105",
"country": "US"
},
"marketing_consent": true,
"customer_tier": "gold",
"referral_source": "paid_search",
"notes": "High-value enterprise customer",
"tags": ["enterprise", "tech", "high-value"],
"custom_fields": {
"company_name": "Tech Corp",
"job_title": "CTO",
"industry": "Technology"
},
"preferences": {
"email_notifications": true,
"sms_notifications": false,
"language": "en",
"timezone": "America/Los_Angeles"
}
}'
import { StateSetClient } from 'stateset-node';
const client = new StateSetClient({
apiKey: process.env.STATESET_API_KEY
});
try {
const customer = await client.customers.create({
email: 'john.doe@example.com',
first_name: 'John',
last_name: 'Doe',
phone: '+1-555-123-4567',
address: {
street1: '123 Main Street',
city: 'New York',
state: 'NY',
postal_code: '10001',
country: 'US'
},
marketing_consent: true,
customer_tier: 'silver',
tags: ['newsletter-subscriber']
});
console.log('Customer created:', customer.id);
// Optionally, create a welcome email workflow
await client.workflows.trigger({
workflow_id: 'welcome_series',
customer_id: customer.id
});
} catch (error) {
if (error.code === 'DUPLICATE_EMAIL') {
console.log('Customer already exists with this email');
} else {
console.error('Error creating customer:', error.message);
}
}
from stateset import StateSet
import os
client = StateSet(api_key=os.getenv('STATESET_API_KEY'))
try:
customer = client.customers.create({
'email': 'jane.smith@example.com',
'first_name': 'Jane',
'last_name': 'Smith',
'phone': '+1-555-234-5678',
'address': {
'street1': '456 Oak Avenue',
'city': 'Los Angeles',
'state': 'CA',
'postal_code': '90210',
'country': 'US'
},
'marketing_consent': False,
'customer_tier': 'bronze',
'referral_source': 'social_media',
'custom_fields': {
'how_did_you_hear': 'Instagram ad',
'interests': 'sustainability'
}
})
print(f'Customer created: {customer.id}')
# Send welcome email
client.emails.send({
'template': 'welcome',
'to': customer.email,
'variables': {
'first_name': customer.first_name
}
})
except Exception as error:
if hasattr(error, 'code') and error.code == 'DUPLICATE_EMAIL':
print('Customer already exists')
else:
print(f'Error: {str(error)}')
require 'stateset'
client = StateSet::Client.new(
api_key: ENV['STATESET_API_KEY']
)
begin
customer = client.customers.create({
email: 'mike.johnson@example.com',
first_name: 'Mike',
last_name: 'Johnson',
phone: '+1-555-345-6789',
address: {
street1: '789 Pine Street',
city: 'Seattle',
state: 'WA',
postal_code: '98101',
country: 'US'
},
customer_tier: 'platinum',
tags: ['vip', 'longtime-customer']
})
puts "Customer created: #{customer.id}"
rescue StateSet::DuplicateEmailError
puts "Customer already exists with this email"
rescue StateSet::Error => e
puts "Error creating customer: #{e.message}"
end
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/stateset/stateset-go"
"github.com/stateset/stateset-go/option"
)
func main() {
client := stateset.NewClient(
option.WithAPIKey(os.Getenv("STATESET_API_KEY")),
)
customer, err := client.Customers.Create(context.Background(), &stateset.CustomerCreateParams{
Email: "alex.brown@example.com",
FirstName: "Alex",
LastName: "Brown",
Phone: "+1-555-456-7890",
Address: &stateset.AddressParams{
Street1: "321 Elm Street",
City: "Austin",
State: "TX",
PostalCode: "73301",
Country: "US",
},
MarketingConsent: stateset.Bool(true),
CustomerTier: stateset.String("gold"),
Tags: []string{"referral", "premium"},
})
if err != nil {
var apiErr *stateset.Error
if errors.As(err, &apiErr) && apiErr.Code == "DUPLICATE_EMAIL" {
fmt.Println("Customer already exists")
return
}
log.Fatal(err)
}
fmt.Printf("Customer created: %s\n", customer.ID)
}
<?php
require_once 'vendor/autoload.php';
use StateSet\StateSetClient;
use StateSet\Exception\StateSetException;
$client = new StateSetClient([
'api_key' => $_ENV['STATESET_API_KEY']
]);
try {
$customer = $client->customers->create([
'email' => 'lisa.davis@example.com',
'first_name' => 'Lisa',
'last_name' => 'Davis',
'phone' => '+1-555-567-8901',
'address' => [
'street1' => '654 Maple Drive',
'city' => 'Denver',
'state' => 'CO',
'postal_code' => '80202',
'country' => 'US'
],
'customer_tier' => 'silver',
'marketing_consent' => true,
'referral_source' => 'email'
]);
echo "Customer created: " . $customer->id . "\n";
// Send welcome SMS if phone provided
if ($customer->phone) {
$client->sms->send([
'to' => $customer->phone,
'message' => "Welcome to our store, {$customer->first_name}!"
]);
}
} catch (StateSetException $e) {
if ($e->getCode() === 'DUPLICATE_EMAIL') {
echo "Customer already exists\n";
} else {
echo "Error: " . $e->getMessage() . "\n";
}
}
?>
import com.stateset.StateSetClient;
import com.stateset.models.Customer;
import com.stateset.models.CustomerCreateParams;
import com.stateset.models.Address;
import com.stateset.exception.StateSetException;
public class CreateCustomerExample {
public static void main(String[] args) {
StateSetClient client = StateSetClient.builder()
.apiKey(System.getenv("STATESET_API_KEY"))
.build();
try {
CustomerCreateParams params = CustomerCreateParams.builder()
.email("tom.wilson@example.com")
.firstName("Tom")
.lastName("Wilson")
.phone("+1-555-678-9012")
.address(Address.builder()
.street1("987 Oak Boulevard")
.city("Miami")
.state("FL")
.postalCode("33101")
.country("US")
.build())
.customerTier("gold")
.marketingConsent(true)
.addTag("newsletter")
.addTag("loyalty-program")
.build();
Customer customer = client.customers().create(params);
System.out.println("Customer created: " + customer.getId());
} catch (StateSetException e) {
if ("DUPLICATE_EMAIL".equals(e.getCode())) {
System.out.println("Customer already exists");
} else {
System.err.println("Error: " + e.getMessage());
}
}
}
}
mutation CreateCustomer($input: CustomerCreateInput!) {
createCustomer(input: $input) {
id
email
firstName
lastName
fullName
phone
address {
street1
street2
city
state
postalCode
country
}
customerTier
marketingConsent
status
createdAt
stripeCustomerId
tags
customFields
preferences {
emailNotifications
smsNotifications
language
timezone
}
}
}
# Variables:
{
"input": {
"email": "emily.chen@example.com",
"firstName": "Emily",
"lastName": "Chen",
"phone": "+1-555-789-0123",
"address": {
"street1": "159 Innovation Way",
"city": "Boston",
"state": "MA",
"postalCode": "02101",
"country": "US"
},
"customerTier": "platinum",
"marketingConsent": true,
"tags": ["enterprise", "tech-executive"],
"customFields": {
"company": "Innovation Labs",
"role": "VP Engineering"
}
}
}
{
"id": "cust_1NXWPnCo6bFb1KQto6C8OWvE",
"email": "sarah.wilson@techcorp.com",
"first_name": "Sarah",
"last_name": "Wilson",
"full_name": "Sarah Wilson",
"phone": "+1-555-987-6543",
"date_of_birth": "1985-12-03",
"address": {
"street1": "123 Innovation Drive",
"street2": "Suite 200",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105",
"country": "US"
},
"customer_tier": "gold",
"marketing_consent": true,
"referral_source": "paid_search",
"stripe_customer_id": "cus_ABC123DEF456",
"status": "active",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"lifetime_value": 0.00,
"total_orders": 0,
"tags": ["enterprise", "tech", "high-value"],
"custom_fields": {
"company_name": "Tech Corp",
"job_title": "CTO",
"industry": "Technology"
},
"preferences": {
"email_notifications": true,
"sms_notifications": false,
"language": "en",
"timezone": "America/Los_Angeles"
}
}
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"errors": [
{
"field": "email",
"message": "Invalid email format",
"value": "invalid-email"
},
{
"field": "first_name",
"message": "First name is required",
"value": null
}
],
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
{
"error": {
"code": "DUPLICATE_EMAIL",
"message": "A customer with this email already exists",
"details": {
"email": "sarah.wilson@techcorp.com",
"existing_customer_id": "cust_2OYZRpEq8dHd3MSvq8E0QYwG"
},
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
{
"error": {
"code": "BUSINESS_RULE_VIOLATION",
"message": "Customer creation violates business rules",
"errors": [
{
"rule": "age_restriction",
"message": "Customer must be at least 13 years old",
"field": "date_of_birth"
}
],
"request_id": "req_1NXWPnCo6bFb1KQto6C8OWvE"
}
}
Additional Features
Idempotency
Use theIdempotency-Key header to safely retry customer creation requests:
curl -X POST https://api.stateset.com/api/v1/customers \
-H "Idempotency-Key: customer-signup-form-abc123" \
-H "Authorization: Bearer sk_live_..." \
-d '{"email": "customer@example.com", ...}'
Stripe Integration
When Stripe integration is enabled:- A Stripe customer is automatically created if
stripe_customer_idis not provided - Customer data is synced between StateSet and Stripe
- Payment methods can be attached to the Stripe customer
Webhook Events
Creating a customer triggers these webhook events:customer.created- Fired when customer is successfully createdcustomer.stripe_synced- Fired when Stripe customer is created (if integration enabled)
Validation Rules
| Field | Validation |
|---|---|
email | Must be valid email format, unique across account |
first_name | 1-50 characters, letters and spaces only |
last_name | 1-50 characters, letters and spaces only |
phone | Valid phone number format |
date_of_birth | Valid date, customer must be at least 13 years old |
postal_code | Valid format for specified country |
country | Valid ISO 3166-1 alpha-2 country code |
Rate Limiting
Customer creation is subject to rate limits:- Standard: 100 customers/minute
- Enterprise: 1000 customers/minute
⌘I