Discount Title in Fulfillments object of Order By Id GraphQL Api

Hi,

I want to fetch the discount title using GetOrderById API , but its not their inside Order–>fulfillments –> fulfillmentLineItems–>nodes–>lineItem–>discountAllocations –>discountApplication

Please guide how to get the discount title using Get Order Graphql API. API Reference Order - GraphQL Admin

1 Like

Hey @Maulik_Shah_RAB, the title field isn’t on the base DiscountApplication type. You’ll need to use inline fragments to access the type-specific fields.

Here’s what the query looks like through your fulfillment path:

order(id: "gid://shopify/Order/123") {
  fulfillments {
    fulfillmentLineItems(first: 10) {
      nodes {
        lineItem {
          discountAllocations {
            discountApplication {
              __typename
              ... on AutomaticDiscountApplication {
                title
              }
              ... on ManualDiscountApplication {
                title
              }
              ... on ScriptDiscountApplication {
                title
              }
              ... on DiscountCodeApplication {
                code
              }
            }
          }
        }
      }
    }
  }
}

One thing to note, DiscountCodeApplication uses code instead of title. It returns the actual discount code that was entered. The other types (automatic, manual, script) all have a title field.

Thanks for your help. it worked.

1 Like