πŸ‘₯Customers

πŸ’‘ Bulk upsert customers for a tenant with a single API call


πŸš€ TL;DR - Quick Reference

Endpoint: POST /customers/{tenantId}

Use When:

  • New customer signup (no purchase)

  • Updating customer preferences

  • Syncing customer profiles from your system

  • GDPR opt-in/opt-out updates

Required: At least one of CustomerId or Email Auth: x-replenit-auth-key header Returns: Count of upserted customers

Quickest Example:

POST /customers/{YOUR_TENANT_ID}
[{"CustomerId": "C-001", "Email": "user@example.com"}]

Jump to Full API Reference ↓


πŸ”— Endpoint

πŸ“‹ Parameters

Parameter
Type
Required
Description

tenantId

GUID

βœ… Yes

The tenant identifier (must exist)

πŸ“¨ Request

  • Body: JSON array of UpsertCustomerDto objects

  • Content-Type: application/json

βœ… Success Response

  • Status: 200 OK

  • Body: Response envelope with data.count

❌ Error Responses

Status
Description

400 Bad Request

Invalid or missing tenant identifier

404 Not Found

Tenant does not exist in our system

500 Internal Server Error

Unexpected server errors


🎯 Identifier Behavior

Understanding how customer identifiers work is crucial for successful data synchronization.

How Customer Matching Works

When you send customer data, the system needs to determine whether you're creating a new customer or updating an existing one. This is done using an identifier field.

Your tenant configuration specifies which field takes priority:

Priority Setting
Identifier Used
When to Use

email

Customer's email address

Best for B2C where emails are unique and stable

customerid

Customer's ID from your system

Best for B2B or when emails can change

What This Means for You

If priority is email:

  • The system matches customers by their email address

  • If an email already exists, that customer record is updated

  • If the email is new, a new customer is created

  • CustomerId can be provided but won't be used for matching

If priority is customerid:

  • The system matches customers by your internal customer ID

  • If the ID already exists, that customer record is updated

  • If the ID is new, a new customer is created

  • Email can be provided but won't be used for matching

Best Practice

Always provide both CustomerId and Email when possible. This ensures:

  • Proper matching based on your tenant's configuration

  • Complete customer profiles

  • Better campaign personalization

  • Reliable customer identification even if one identifier changes

Example:

πŸ“ Note: To view or change your identifier priority setting, navigate to your tenant configuration in the Replenit Dashboard.


πŸ“„ Request Schema

UpsertCustomerDto Fields

All fields are optional unless specified otherwise. The API uses intelligent defaults for missing values.

Field
Type
Max Length
Required
Description

CustomerId

string

100

⚠️ Conditional

Your unique identifier for this customer. Either this or Email is required depending on tenant settings.

Email

string

255

⚠️ Conditional

Customer's email address. Either this or CustomerId is required depending on tenant settings.

Name

string

100

❌

Customer's first name. Used in email personalization and campaign targeting.

Surname

string

300

❌

Customer's last name. Combined with Name for full personalization.

Phone

string

20

❌

Customer's phone number. Required for SMS campaigns. Can include country code.

Language

string

10

❌

Preferred language using IETF BCP 47 format (e.g., en-US, fr-FR). Determines campaign language.

Username

string

500

❌

Customer's username in your system. Useful for app-based businesses.

EmailOptin

bool

-

❌

Whether customer consented to email marketing. Default: false. Required for email campaigns.

SmsOptin

bool

-

❌

Whether customer consented to SMS marketing. Default: false. Required for SMS campaigns.

WhatsappOptin

bool

-

❌

Whether customer consented to WhatsApp messaging. Default: false. Required for WhatsApp campaigns.

AppPushOptin

bool

-

❌

Whether customer consented to app push notifications. Default: false. Required for push campaigns.

GdprOptin

bool

-

❌

Whether customer provided GDPR consent. Default: false. Important for EU compliance.

IsExcluded

bool

-

❌

Exclude this customer from all campaigns. Default: false. Useful for VIP manual-only communication.

Field Notes

Consent Fields (EmailOptin, SmsOptin, etc.):

  • These control which communication channels are enabled for this customer

  • Always respect customer preferences - sending to non-opted-in customers may violate regulations

  • Update these fields when customers change their preferences

Language Field:

  • Use standard language codes like en, de, fr

  • Or region-specific codes like en-US, es-MX, pt-BR

  • If omitted, campaigns will use your default language

GDPR Compliance:

  • The GdprOptin field is critical for EU customers

  • Set to true only after obtaining explicit consent

  • When false, customer data is stored but marketing is restricted


πŸ—‘οΈ DELETE Endpoint

πŸ”— Delete Customer

πŸ“‹ Parameters

Parameter
Type
Required
Description

tenantId

GUID

βœ… Yes

The tenant identifier

customerId

string

βœ… Yes

The customer ID to delete

βœ… Success Response

  • Status: 200 OK

  • Body: Response envelope with deleted customer ID

❌ Error Responses

|| Status | Scenario | Example Response | || ------ | -------- | ---------------- | || 400 | Missing customer ID | {"success": false, "message": "Customer ID is required.", "data": {}} | || 404 | Tenant not found | {"success": false, "message": "Tenant not found.", "data": {}} | || 404 | Customer not found | {"success": false, "message": "Customer not found.", "data": {}} | || 500 | Storage failure | {"success": false, "message": "Failed to delete customer.", "data": {}} |

Note: The tenant validation is performed automatically by middleware before reaching the endpoint. If tenant doesn't exist, you'll receive a 404 error immediately.

πŸš€ DELETE Examples

cURL

Python

Node.js


πŸ’‘ Real-World Use Cases

Use Case 1: E-commerce Customer Signup

Scenario: Customer creates account on your website (no purchase yet)

What to send:

What happens:

  1. βœ… Customer profile created in Replenit

  2. 🎯 Added to "Welcome" campaign

  3. πŸ“§ Receives welcome email series


Use Case 2: Newsletter Subscription

Scenario: User subscribes to newsletter without creating account

What to send:

Why minimal fields: You only have email, that's enough!


Use Case 3: GDPR Opt-Out

Scenario: Customer requests to stop receiving emails

What to send:

What happens:

  1. βœ… Customer preferences updated

  2. 🚫 Removed from all marketing campaigns

  3. βœ… GDPR compliance maintained


Use Case 4: Bulk Customer Import

Scenario: Migrating 10,000 customers from old system

Best practice:

Performance: ~20 batches = ~10 seconds total (vs 10,000 individual calls = 30+ minutes)


πŸ“ Complete Example Request (All Fields)

πŸ“ Minimal Example Request (Required Fields Only)

πŸ“ Email-Based Customer (When Priority is Email)

πŸš€ cURL Example

🐍 Python Example

🟒 Node.js Example


πŸ“Š Response Examples

βœ… Success Response (200)

❌ Validation Error (400) - Missing Identifier (CustomerId or Email)

πŸ“– What this means:

  • You must provide at least one identifier: either CustomerId OR Email

  • This validation ensures we can identify the customer in our system

  • Both can be provided for better data quality

βœ… How to fix:

Or with email:

Best practice (both identifiers):

πŸ’‘ Common causes:

  • Sending empty customer object {}

  • Both CustomerId and Email are null, empty string, or omitted

  • Whitespace-only values in identifier fields


❌ Validation Error (400) - Missing Required Fields

πŸ“– What this means:

  • Your first customer (index [0]) is missing required fields

  • Note: These fields are only required if your tenant configuration enforces them

  • Check your tenant settings to see which fields are mandatory

βœ… How to fix:

πŸ’‘ Common causes:

  • Missing Language field (use IETF BCP 47 format: en-US, de-DE, etc.)

  • Missing GdprOptin field (must be true or false, not omitted)

  • Tenant configuration requires these fields

❌ Validation Error (400) - String Length Exceeded

πŸ“– What this means:

  • Field values exceed maximum allowed length

  • CustomerId: maximum 100 characters

  • Language: maximum 10 characters

βœ… How to fix:

  • Use shorter customer IDs

  • Use standard language codes (e.g., en-US instead of long text)

πŸ’‘ Field length limits:

Field
Max Length

CustomerId, Name, Surname

100

Username

500

Email

255

Phone

20

Language

10

❌ Not Found (404)

❌ Internal Server Error (500)


πŸ” Best Practices

  1. Batch Operations: Send multiple customers in a single request for better performance (recommended batch size: 100-500)

  2. Validation: Ensure email addresses are valid before submission

  3. GDPR Compliance: Always obtain proper consent before setting opt-in flags

  4. Error Handling: Implement retry logic for 500 errors with exponential backoff

  5. Rate Limiting: Respect API rate limits to avoid throttling

  6. CustomerId: Please ensure that it is also set as an identifier in your Marketing Automation platform, so users can be consistently matched across systems and events

  7. Language Format: Use IETF language tags (BCP 47) format:

    • Examples: en, en-US, en-GB, es-ES, fr-FR, de-DE, pt-BR

    • Pattern: language[-script][-region]


Last updated