How to merge Shopify profiles with the API and fix bad emails due to typos

The Challenge

In our Shopify store, we faced the issue of having a large number of customer profiles with incorrect email domains. These were often due to minor typos or spelling errors, which could create issues like failed email deliveries and duplicate profiles. We had over 2,500 such customer profiles that needed cleaning.

The Solution

Shopify provides a Customer Merge GraphQL API that allows for merging two customer profiles into one. We utilized this API to merge profiles where the email domain had typos with those of correct email domains.

The Strategy

  1. Generate all possible variations of known correct email domains within an edit distance of 1 and 2. For example, gmail.com could have variations like gmaail.com, gmial.com, etc.
  2. Use these variations to identify customer profiles that are likely incorrect.
  3. Merge these profiles with the correct ones if they exist; otherwise, update the email to the correct domain.

Code Snippet

Here's the code snippet that shows how we accomplished this: 

 

Conclusion

Using Shopify's Customer Merge API and some Python scripting, we were able to clean up over 2,500 customer profiles with incorrect email domains. This not only improved the integrity of our customer data but also helped in enhancing the customer experience by ensuring that all future communications reach the correct recipient.

Back to blog