GraphQL API Discounts: download all non personal discount codes

Topic summary

A developer needs to filter GraphQL API queries to retrieve only non-personal discount codes, excluding customer-specific ones.

Current approach:

  • Downloads ALL active discount codes via discountNodes query
  • Manually filters by checking if customerSelection is empty (indicating codes available to all customers)

Problem:

  • Some apps generate individual discount codes per buyer, creating massive volumes of personal codes
  • These personal codes are irrelevant to their application and cause performance/data issues

Goal:

  • Find a way to filter out personal discount codes directly in the GraphQL query rather than post-processing
  • Only retrieve discount codes intended for all customers

The discussion remains open with no solution provided yet. The code snippet shows their current query structure using DiscountCodeBasic and DiscountCustomerAll types.

Summarized with AI on October 30. AI used: claude-sonnet-4-5-20250929.

We need to download all non personal discount codes using GraphQL API.

At the moment we download ALL discounts and check if the customerSelection is empty. This means that the code is for all customers. Below is the gist of the query. We would like to filter out all discounts which are personal, because in some cases apps generate discount codes for each buyer and this generated a huge amount of code which are useless for our app.

{
    discountNodes(query:"status:active") {
        edges {
            node {
                id
                discount {
                    __typename
                    ... on DiscountCodeBasic {
                        title
                        summary
                        ## more fields ##
                        customerSelection {
                            ... on DiscountCustomerAll {
                                allCustomers
                            }
                        }
                        discountClass
                        status
                    }
                }
            }
        }
    }
}