Discount codes by a customer ID or email

Topic summary

A developer is attempting to filter discount codes by customer ID or email address using Shopify’s Admin GraphQL API. While they can retrieve all discount codes, they cannot limit results to a specific logged-in user.

Proposed Solution:

  • Use the customersSelection field on the DiscountNode object
  • This field provides access to customer-specific discount information
  • Example query structure involves accessing codeDiscountNodeByCode, then using customersSelection to filter by customer details (ID, firstName, etc.)

Technical Details:

  • The query involves nested fields: DiscountCodeBasiccodescustomersSelectioncustomers
  • The customersSelection field appears to be the key filtering mechanism for customer-specific discounts

Status: A solution has been provided, though implementation confirmation is pending.

Summarized with AI on November 17. AI used: claude-sonnet-4-5-20250929.

I am trying to select discount codes assigned to a logged-in user using admin graphql API. I am able to select all discount codes but I am not able to filter them by customer ID or customer email address. Here is my GQL. Can you guide me on how can limit the results to specified customers?

{
  priceRules(first: 10, reverse: true) {
    nodes {
      customerSelection {
        customers(first: 10) {
          edges {
            node {
              id
              email
            }
          }
        }
      }
      title
    }
  }
}

Hi there :waving_hand:

You can use the customersSelection on the DiscountNode object.

{
  codeDiscountNodeByCode(code: "CODE") {
    codeDiscount {
      ... on DiscountCodeBasic {
        codes(first: 5) {
          nodes {
            code
          }
        }
        customerSelection {
          ... on DiscountCustomers {
            customers {
              firstName
              id
            }
          }
        }
      }
    }
  }
}
1 Like