Retrieving Discount names in Order

My client is using GraphQL API to retrieve Orders. They would like to retrieve the Discount name that is used in the Order. Looking at the docs I can’t seem to find a way to get this? I see that discountApplications will itemize the discounts in a order but there doesn’t seem to be a way to get the name of each. Is there something I’m missing? Thanks.

Also, discount codes don’t show up either in the discountCode or discountCodes fields. What discountCode is that referring to?

Hey @Frederick_Wells,

discountApplications does give you discount names directly for most discount types! The key is using fragments to access the title field that’s available on ManualDiscountApplication, AutomaticDiscountApplication, and ScriptDiscountApplication.

Only DiscountCodeApplication returns just the code field without the discount name.

Here’s the query structure using fragments to get the discount names you’re looking for:

{
  orders(first: 10) {
    edges {
      node {
        id
        discountApplications(first: 10) {
          edges {
            node {
              __typename
              ... on ManualDiscountApplication {
                title
                description
              }
              ... on AutomaticDiscountApplication {
                title
              }
              ... on ScriptDiscountApplication {
                title
              }
              ... on DiscountCodeApplication {
                code
              }
            }
          }
        }
      }
    }
  }
}
1 Like