> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/graphql-api/mutations/deletecustomer.md).

# Delete Customer

Delete Customer Mutation

Deletes an existing customer entity from the system.

## Arguments

| Name | Type  | Description                      |
| ---- | ----- | -------------------------------- |
| `id` | `ID!` | The ID of the customer to delete |

## Return Type

`CustomerDeletePayload!` - Confirmation of the delete operation.

## Return Fields

`CustomerDeletePayload`:

| Field       | Type | Description                    |
| ----------- | ---- | ------------------------------ |
| `deletedID` | `ID` | The ID of the deleted customer |

## Usage Example

```graphql
mutation {
  deleteCustomer(id: "cust_123456789") {
    deletedID
  }
}
```

```graphql
mutation {
  # Delete multiple customers (requires multiple calls)
  deleteCustomer1: deleteCustomer(id: "cust_111111111") {
    deletedID
  }
  deleteCustomer2: deleteCustomer(id: "cust_222222222") {
    deletedID
  }
  deleteCustomer3: deleteCustomer(id: "cust_333333333") {
    deletedID
  }
}
```

## JavaScript Example

```javascript
const DELETE_CUSTOMER = gql`
  mutation DeleteCustomer($id: ID!) {
    deleteCustomer(id: $id) {
      deletedID
    }
  }
`;

// Using the mutation
const [deleteCustomer] = useMutation(DELETE_CUSTOMER);

const handleDeleteCustomer = async (customerId) => {
  try {
    const { data } = await deleteCustomer({
      variables: { id: customerId }
    });
    
    console.log('Customer deleted:', data.deleteCustomer.deletedID);
    // Update UI to remove the deleted customer
  } catch (error) {
    console.error('Error deleting customer:', error);
  }
};
```

## Important Considerations

### Soft vs Hard Delete

The pyck system implements soft deletes by default, meaning:

* The customer record is marked as deleted (`deletedAt` timestamp is set)
* The customer data remains in the database for audit purposes
* The customer will not appear in normal queries
* Related data (orders, transactions) remains intact

### Data Integrity

Before deleting a customer, consider:

* **Active Orders**: Check if the customer has pending or active orders
* **Outstanding Invoices**: Verify all invoices are settled
* **Related Records**: Consider impact on order history, payments, and analytics
* **Audit Requirements**: Ensure deletion complies with business audit needs

### Permissions

Customer deletion typically requires:

* Administrative privileges
* Proper authorization for the tenant/organization
* Compliance with data retention policies

## Error Scenarios

The mutation may fail in these cases:

* **Not Found**: Customer ID doesn't exist
* **Permission Denied**: Insufficient privileges to delete customers
* **Constraint Violations**: Customer has dependent records that prevent deletion
* **Business Rules**: Custom business logic prevents deletion

## Best Practices

1. **Confirmation**: Always confirm deletion with users before executing
2. **Backup**: Consider exporting customer data before deletion
3. **Audit Trail**: Log deletion operations for compliance
4. **Bulk Operations**: For multiple deletions, implement proper error handling
5. **Related Cleanup**: Plan for cleanup of related customer data if needed

## Alternative Approaches

Instead of deletion, consider:

* **Deactivation**: Mark customer as inactive rather than deleting
* **Archiving**: Move old customers to an archived status
* **Data Anonymization**: Remove personal data while keeping transaction history


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/graphql-api/mutations/deletecustomer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
