Can't find customer by email

Highlighted
New Member
2 0 0

I'm using the API to search for existing customers using their email. The main idea is that if the customer doesn't exist, my system will automatically create it. The problem is that the endpoint is returning 0 coincidences when searching by email, but if I try to create the customer object, Shopify returns an error because the email is already in use. 

 

I tried looking for the customer in the admin, and it was only found if searched by name. I also tried reaching the support team and they could find the user by email, after they asked me to try again the user was successfully retrieved. I was given no solution and they didn't know what made it work. Anyways, my system needs to verify if the customer exists to decide if it should create it or not.

 

Any ideas why this could be happening?

 

The endpoint I'm using:

/admin/api/2020-01/customers/search.json?query=email:<email>

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 130

Hi @oscar-sanjim ,

 

If all you need to search by email address then you can drop the `email` part of the query string and just put the email address only. I tested this out on my test store and it worked as expected:

GET {store-name).myshopify.com/admin/api/2020-04/customers/search.json?query={email address}

 

Alternatively, you can also do this very easily in the GraphQL Admin API:

{
  customers(first:10, query:"email:'test@example.com") {
    edges {
      node {
        id
        verifiedEmail
        firstName
        lastName
      }
    }
  }
}

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

Highlighted
New Member
2 0 0

Hi Hassain,

 

When I had this issue, I tested both formats of the query:

 

{store-name).myshopify.com/admin/api/2020-04/customers/search.json?query={email address}

{store-name).myshopify.com/admin/api/2020-04/customers/search.json?query=email:{email address}

Could it be possible that this endpoint requires some time to update before retrieving the recently created users?

 

 

 

 

0 Likes
Highlighted
Shopify Partner
3 0 0

Try to use graphql.

I've also faced the same issue but I just run graphql query and I get what I wanted...

0 Likes