Delete Customer

The Delete Customer endpoint allows you to permanently remove a customer from your system. This operation is irreversible and includes comprehensive validation and audit trail logging for security and compliance purposes.

⚠️ Important Notice: Customer deletion may fail if the customer has associated records such as invoices or payment links. The system maintains referential integrity to prevent data corruption.

Endpoint DetailsCopied!

  • Method: DELETE

  • URL: /api/v0/customers/{id}

  • Content-Type: application/json

  • Authentication: Required (x-client-key and x-client-secret)

Path ParametersCopied!

Parameter

Type

Required

Description

id

string

Yes

The unique UUID of the customer to delete

Request HeadersCopied!

Header

Type

Required

Description

x-client-key

string

Yes

Your API client key

x-client-secret

string

Yes

Your API client secret

idempotency-key

string

Yes

Unique UUID for request idempotency

ResponseCopied!

Success Response (200 OK)

{
  "id": "customer_uuid",
  "first_name": "John",
  "last_name": "Doe",
  "email": "john.doe@example.com",
  "phone_number": "+1234567890",
  "status": "ACTIVE",
  "customer_type": "Individual",
  "last_spent": 150.75,
  "last_purchase_date": "2024-01-15T10:30:00Z",
  "appId": "app_uuid",
  "createdAt": "2024-01-01T00:00:00Z",
  "updatedAt": "2024-01-15T10:30:00Z"
}

Error Responses

400 Bad Request - Customer Has Associated Records
{
  "statusCode": 400,
  "message": "Customer cannot be deleted.",
  "error": "Bad Request"
}
404 Not Found - Customer Not Found
{
  "statusCode": 404,
  "message": "Customer not found",
  "error": "Not Found"
}
429 Too Many Requests
{
  "statusCode": 429,
  "message": "Rate limit exceeded",
  "error": "Too Many Requests"
}

Business Logic & ConstraintsCopied!

Deletion Restrictions

Customer deletion will fail if the customer has:

  • Active Invoices: Any invoices (draft, pending, or paid) associated with the customer

  • Payment Links: Payment links specifically created for the customer

  • Transaction History: Associated transaction records

  • Related Financial Records: Any other financial data tied to the customer

Data Integrity Protection

The system uses foreign key constraints to maintain referential integrity:

  • Primary Constraint: Customer.id referenced by multiple tables

  • Error Code: P2003 (Foreign key constraint violation)

  • Behavior: Operation fails gracefully with descriptive error message

Audit Trail

Every deletion attempt (successful or failed) is logged with:

  • User Information: Who performed the action

  • Customer Details: Full customer record before deletion

  • Timestamp: When the action occurred

  • Request Context: IP address, user agent, and request details

  • Outcome: Success or failure with error details

Example RequestsCopied!

Delete Customer

curl -X DELETE "https://api.devdraft.com/api/v0/customers/550e8400-e29b-41d4-a716-446655440000" \
  -H "x-client-key: your_client_key" \
  -H "x-client-secret: your_client_secret" \
  -H "idempotency-key: 550e8400-e29b-41d4-a716-446655440001"

Example Success Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "first_name": "John",
  "last_name": "Doe",
  "email": "john.doe@example.com",
  "phone_number": "+1234567890",
  "status": "ACTIVE",
  "customer_type": "Individual",
  "last_spent": 250.00,
  "last_purchase_date": "2024-01-20T14:30:00Z",
  "appId": "app_550e8400-e29b-41d4-a716-446655440000",
  "createdAt": "2024-01-01T00:00:00Z",
  "updatedAt": "2024-01-20T14:30:00Z"
}

Integration Best PracticesCopied!

Pre-Deletion Verification

Before attempting to delete a customer:

  1. Check Customer Status: Verify the customer exists and belongs to your app

  2. Review Associated Data: List customer's invoices, payment links, and transactions

  3. Business Logic: Ensure deletion aligns with your business requirements

Error Handling

try {
  const response = await fetch('/api/v0/customers/customer_id', {
    method: 'DELETE',
    headers: {
      'x-client-key': 'your_client_key',
      'x-client-secret': 'your_client_secret',
      'idempotency-key': 'unique_uuid'
    }
  });
  
  if (response.status === 400) {
    // Customer has associated records - handle gracefully
    console.log('Customer cannot be deleted due to associated records');
  } else if (response.ok) {
    const deletedCustomer = await response.json();
    console.log('Customer deleted successfully:', deletedCustomer);
  }
} catch (error) {
  console.error('Deletion failed:', error);
}

Alternative Actions

If deletion fails due to constraints, consider:

  1. Blacklist Customer: Update status to BLACKLISTED instead of deletion

  2. Deactivate Customer: Change status to DEACTIVATED

  3. Data Archival: Move customer to archived status while preserving data integrity

Security Considerations

  • Permissions: Ensure proper role-based access control

  • Audit Compliance: All deletion attempts are logged for compliance

  • Data Privacy: Consider GDPR/privacy implications before deletion

  • Backup Strategy: Maintain data backups for recovery if needed

Rate LimitingCopied!

  • Limit: 100 requests per minute per API key

  • Headers: Check X-RateLimit-* headers in response

  • Best Practice: Implement exponential backoff for rate limit errors

SupportCopied!

For technical support or questions about customer deletion:

  • Check audit trail logs for detailed error information

  • Review customer's associated records before deletion attempts

  • Contact support with specific customer ID and error details