Learn how to delete a Customer with the commercetools SDKs.
After completing this page, you should be able to:
- Identify the correct process for deleting a Customer with the commercetools SDKs.
Our customer John Doe has requested to be removed from our webshop. Let's comply with his wish and delete him. If you have to follow such requests, make sure you read our advice on complying with public regulations such as the European Union's Data Protection Regulation (GDPR).
To delete a resource in Composable Commerce, you identify the resource with its
key
or id
and then send a DELETE call when using the REST API, together with the correct version. For Customers, see our documentation on deleting Customers.An example request would be:
DELETE https://api.{region}.commercetools.com/{projectKey}/customers/key={key}?version={version}
Authorization: Bearer my_token
Use the SDKs
TypeScript
Java
Create a file called
customerDelete.js
and copy the following code:import { apiRoot } from '../impl/apiClient.js'; // Update to map to your API root
const customerKey = 'john-doe-example';
// Change the version number if necessary
const customerVersion = 1;
async function customerDeleteByKey(customerKey, customerVersion) {
try {
const response = await apiRoot
.customers()
.withKey({ key: customerKey })
.delete({
queryArgs: {
version: customerVersion,
},
})
.execute();
console.log('Success', JSON.stringify(response.body, null, 2));
} catch (error) {
console.log(JSON.stringify(error, null, 2));
}
}
customerDeleteByKey(customerKey, customerVersion);
Don’t forget to verify in the Merchant Center or programmatically that the Customer has indeed been deleted.