GraphQL Pull Entitled Discounts

Topic summary

A user encountered an issue querying order discount information via GraphQL where coupon titles and descriptions were missing for discounts with allocationMethod: ACROSS and targetSelection: ENTITLED, despite appearing correctly in REST API responses.

Problem Details:

  • GraphQL query returned title/description for EXPLICIT allocation method but not for ACROSS
  • REST API consistently returned all discount metadata including title
  • The discount type was automatic with 55% percentage value

Resolution:
The issue was resolved by adding the missing AutomaticDiscountApplication fragment to the GraphQL query. The user’s original query included fragments for DiscountCodeApplication, ManualDiscountApplication, and ScriptDiscountApplication, but omitted AutomaticDiscountApplication.

Key Takeaway:
Each discount type in GraphQL has a specific __typename that requires its corresponding fragment in the query. For automatic discounts, the AutomaticDiscountApplication fragment must be explicitly included to retrieve all fields like title and description.

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

I am querying orders. I want to see what coupon code was used.

When the coupon allocationMethod is EXPLICIT, I see a title and a description. When the allocation method is ACROSS, I see no title and description.

When I use REST, the title and description is populated on all orders. This is a graph QL issue only.

Here is the discount in REST:

{"target_type":"line_item","type":"automatic","value":"55.0","value_type":"percentage","allocation_method":"across","target_selection":"entitled","title":"EMPLOYEE

Here is my query:

discountApplications(first: 100) {
  edges {
    node {
      value {
        ... on MoneyV2 {
          __typename
          amount
          currencyCode
        }
        ... on PricingPercentageValue {
          __typename
          percentage
        }
      }
      allocationMethod
      index
      targetSelection
      targetType
      ... on DiscountCodeApplication {
        __typename
        code
        allocationMethod
        index
        targetSelection
        targetType
        value {
          ... on MoneyV2 {
            __typename
            amount
            currencyCode
          }
          ... on PricingPercentageValue {
            __typename
            percentage
          }
        }
      }
      ... on ManualDiscountApplication {
        description
        value {
          ... on MoneyV2 {
            __typename
            currencyCode
            amount
          }
          ... on PricingPercentageValue {
            __typename
            percentage
          }
        }
        allocationMethod
        index
        targetSelection
        targetType
        title
      }
      ... on ScriptDiscountApplication {
        __typename
        allocationMethod
        description
        targetSelection
        index
        targetType
        value {
          ... on MoneyV2 {
            __typename
            currencyCode
            amount
          }
          ... on PricingPercentageValue {
            __typename
            percentage
          }
        }
        title
      }
    }
  }
}

Here is the result:

{
                "node": {
                  "value": {
                    "__typename": "PricingPercentageValue",
                    "percentage": 55.0
                  },
                  "allocationMethod": "ACROSS",
                  "index": 1,
                  "targetSelection": "EXPLICIT",
                  "targetType": "LINE_ITEM",
                  "description": "EMPLOY33S",
                  "title": "EMPLOY33S"
                }
              },
              {
                "node": {
                  "value": {
                    "__typename": "PricingPercentageValue",
                    "percentage": 55.0
                  },
                  "allocationMethod": "ACROSS",
                  "index": 2,
                  "targetSelection": "ENTITLED",
                  "targetType": "LINE_ITEM"
                }
              },

I was missing:

… on AutomaticDiscountApplication {
__typename
allocationMethod
index
targetSelection
targetType
title
value
}

Each discount has an __typename. It it’s AutomaticDiscountApplication, then add the AutomaticDiscountApplication