Optimizing ESHOPMAN Customer Queries: Navigating Phone Number Filters in the Admin API

As an e-commerce platform built on Node.js/TypeScript and deeply integrated with HubSpot for storefront management and CMS deployment, ESHOPMAN offers a robust Admin API for managing various aspects of your store, including customer data. Developers often leverage this API to build custom functionalities, reports, or integrations within the HubSpot ecosystem. However, navigating the nuances of API type definitions can sometimes present unexpected challenges.

Addressing Customer Phone Number Filtering in ESHOPMAN Admin API

A common scenario for ESHOPMAN developers involves querying customer data, often requiring specific filters to refine results. One such challenge recently surfaced regarding the ability to filter customers based on their phone numbers using the ESHOPMAN Admin API.

The Challenge: Missing Phone Property in AdminCustomerFilters

When attempting to retrieve a list of customers from the ESHOPMAN backend, particularly for use in dynamic fields like a ComboBox, developers naturally expect to filter by essential customer properties. While properties like email, first_name, and last_name are readily available for filtering within the AdminCustomerFilters type, the phone property currently presents a TypeScript hurdle. Attempting to include phone directly in the query parameters results in a TypeScript error:

Object literal may only specify known properties, and 'phone' does not exist in type 'AdminCustomerFilters'.

This indicates that despite phone being a valid customer attribute, the current type definition for AdminCustomerFilters in the ESHOPMAN Admin API does not explicitly include it as a filterable property. This can be particularly frustrating when the goal is to, for instance, identify all customers who have a phone number or those who do not.

Expected Behavior vs. Current Implementation

Developers expect the ESHOPMAN Admin API to allow direct filtering on the phone property, similar to how other core customer details are handled. For example, an ideal query might look like this, aiming to retrieve customers with non-null phone numbers:

const res = await sdk.admin.customer.list({ ...params, phone: { $ne: null }, limit: 10 })

However, due to the type definition limitation, this direct approach is currently not viable.

A Practical Workaround for ESHOPMAN Developers

Until the AdminCustomerFilters type definition is updated to include the phone property, ESHOPMAN developers can implement a client-side filtering strategy. This involves fetching a broader set of customer data and then refining the results within the application logic. While this approach might be less efficient for very large datasets (as it requires fetching more data than strictly necessary), it provides an immediate solution for scenarios where precise filtering by phone is critical.

Here’s how a client-side workaround can be implemented:

queryFn: async (params) => {
  const res = await sdk.admin.customer.list({ ...params, limit: 10 });

  // Client-side filtering for customers with valid phone numbers
  const validCustomers = (res.customers ?? []).filter(
    (c) => typeof c.ph "string" && c.phone.trim().length > 0
  );

  validCustomers.forEach((c) => {
    customerMapRef.current.set(c.id, c);
  });

  return {
    ...res,
    customers: validCustomers,
  };
},

In this workaround, the sdk.admin.customer.list call retrieves customers without the phone filter. Subsequently, the fetched customers array is filtered in memory to include only those with a valid phone number. This ensures that your HubSpot CMS storefronts or custom admin interfaces display or process customer data accurately based on phone availability.

Best Practices for ESHOPMAN Integrators

This scenario highlights the importance of understanding both the capabilities and the current limitations of API type definitions in headless commerce platforms like ESHOPMAN. When encountering similar type-related issues, consider these steps:

  • Consult ESHOPMAN Documentation: Always refer to the latest ESHOPMAN Admin API documentation for supported filters and properties.
  • Implement Client-Side Workarounds: For immediate needs, client-side filtering can bridge gaps, especially for smaller to medium datasets.
  • Stay Updated: Keep your ESHOPMAN packages updated to benefit from the latest features and type definition improvements.

The ESHOPMAN platform, with its Node.js/TypeScript foundation, is continuously evolving. Addressing such type definition discrepancies is crucial for maintaining a seamless developer experience and empowering businesses to manage their storefronts effectively within HubSpot.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools