Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

REST API customer search by email yields no results

Solved

REST API customer search by email yields no results

rtsharp
Shopify Partner
2 1 0

I've created a customer record in my development store using the customers API with the following:

 

 

 

await this.client.post({
      path: "/admin/api/2023-04/customers.json",
      data: {
        customer: {
          email: emailAddress,
          tags: ["aTag"],
          email_marketing_consent: {
            state: "subscribed",
            opt_in_level: "confirmed_opt_in",
          },
        },
      },
    });

 

 

 

I've verified the account appears in the customers dashboard for my development store, but when I attempt to search for that customer using the following, I get no results:

 

 

 

await this.client.get({
  path: `/admin/api/2023-04/customers/search.json?query=${encodeURIComponent(
     email:${emailAddress}`
  )}`,
});

 

 

 

 
I have verified getting the account using just the customer ID via the REST API works, but for whatever reason the search query returns no results.

Any ideas what I'm missing or doing wrong?

Accepted Solution (1)
rtsharp
Shopify Partner
2 1 0

This is an accepted solution.

Hi Liam,


I appreciate the quick response! I did a little bit more digging, turns out I was constructing the request incorrectly.  I'm pretty sure I followed the expected format for the query, but after changing it to this, it worked.

await this.client.get({
  path: `/admin/api/2023-04/customers/search.json`,
  query: {
    query: `email:${emailAddress}`,
  },
});

 I guess the client removes any URL parameters applied directly to the path.

View solution in original post

Replies 2 (2)

Liam
Community Manager
3108 344 899

 

Hi Rtsharp,

 

The first thing I'd check is to make sure that the emailAddress is correctly populated and it matches exactly the email address used to create the customer. I'd also make sure you are properly handling the asynchronous nature of the requests Ensure that you are either await-ing the promise or handling it with a .then() block.

 

Also if you're using encodeURIComponent on your query string could this cause the email to be encoded and affect the query? You could try removing encodeURIComponent to see if that makes a difference?

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

rtsharp
Shopify Partner
2 1 0

This is an accepted solution.

Hi Liam,


I appreciate the quick response! I did a little bit more digging, turns out I was constructing the request incorrectly.  I'm pretty sure I followed the expected format for the query, but after changing it to this, it worked.

await this.client.get({
  path: `/admin/api/2023-04/customers/search.json`,
  query: {
    query: `email:${emailAddress}`,
  },
});

 I guess the client removes any URL parameters applied directly to the path.