Is it possible to search customers by company?

In the REST API it lets you search customers by company. But this does not seem possible in the GraphQL API. Is that correct?

REST API docs for customers search:

https://shopify.dev/docs/api/admin-rest/2024-07/resources/customer#get-customers-search?query=email:bob.norman@mail.example.com

GraphQL docs for customers query:

https://shopify.dev/docs/api/admin-graphql/2024-07/queries/customers

Hi Devkev

In the Shopify GraphQL Admin API, there isn’t a direct way to search customers by their company name. The REST API does provide this capability, but the GraphQL API does not currently have an equivalent query parameter for searching customers by company. However, you can achieve a similar result by querying customers and filtering their addresses to check for the company name. Here is an example of how you might do this:

query GetCustomersByCompany {
  customers(first: 50, query: "addresses.company:YourCompanyName") {
    edges {
      node {
        id
        firstName
        lastName
        email
        addresses {
          company
        }
      }
    }
  }
}

Hope this helps!

Thanks for the suggestion! What I ended up doing was using the REST API to search by company and then building a GraphQL customer query using the customer ids from REST. That way I can search by company and still use GraphQLs ability to load related data like addresses and orders.

REST QUERY:

https://your-development-store.myshopify.com/admin/api/2024-07/customers/search.json?fields=id&query=company%3A%22mycompany%22

GraphQL Query:

query {
    customers(first: 50, query: "(id:111111111 OR id:22222222 OR id:333333333)") {
        nodes {
            id
            firstName
            lastName
            emailMarketingConsent {
                marketingState
            }
            addresses {
                company
            }
            defaultAddress {
                city
                provinceCode
                countryCode
            }
            lastOrder {
                processedAt
            }
            numberOfOrders
            amountSpent {
                amount
            }
            tags
        }
        pageInfo {
            hasPreviousPage
            hasNextPage
            startCursor
            endCursor
        }
    }
}

By the way, I tried copying your query into the GraphQL explorer and it gave me “Invalid search field for this query.”

Hi again - I looked into this further and the customer search filters are actually deprecated on GraphQL. Have you looked into using customer segments?

I hadn’t thought of using customer segments. I found this list of attributes that can be queried. But company doesn’t appear to be one of them. What I have now is working well enough I guess. I probably just stick with that. Thanks for the suggestion.