The discount appplications returned by GraphQL order API contains empty object value

Hi all,

I tried getting the discount_applications of the order object on frontend and it works without problem. but retrieving the order.discountApplications thru the graphql order API returns an empty object.

api version: 2022-10

discountApplications array received:

[
  {
    node: {
      value: {},
      index: 0,
      targetType: 'LINE_ITEM',
      targetSelection: 'ENTITLED',
      allocationMethod: 'ACROSS'
    }
  }
]

any help is appreciated. thanks.

There are a few possible reasons for this issue:

  1. The order may not have any discount applications applied to it. In this case, the discountApplications field will be an empty array.

  2. The discountApplications field may not be included in the GraphQL query that you are using. In this case, you will need to include the field in your query to retrieve its value.

  3. There may be an issue with the GraphQL Order API endpoint or with your application’s authentication. In this case, you may need to check the error logs or contact Shopify support for further assistance.

To retrieve the discountApplications field of the order object using the GraphQL Order API, you will need to include the field in your query and ensure that your application is properly authenticated.

You can find more information about the GraphQL Order API in the Shopify documentation.

https://shopify.dev/api/admin-graphql

Thx for your info.

The order does have an discount code entered and i have the discountApplications field in the query.

and i could retrieve other fields of the order, so i think the app permission should have been configured correctly.

i give up using the discountApplications and get the total discount by the totalDiscountsSet field.

1 Like

Hi @ykyuen :waving_hand:

The DiscountApplication is an interface, so you will need to fragment on the types. To query non-code discounts, you can use something like the below:

query ($id: ID!) {
    order (id:$id){
        discountApplications (first:10){
            nodes {
                ... Discounts
            }
        }
    }
}

fragment Discounts on DiscountApplication {
    ... on AutomaticDiscountApplication {
        title
        value {
            ... on MoneyV2 {
                amount
            }
        }
    }
    ... on ScriptDiscountApplication {
        title
        value {
            ... on MoneyV2 {
                amount
            }
        }
    }
    ... on ManualDiscountApplication {
        title
        value {
            ... on MoneyV2 {
                amount
            }
        }
    }
}

Hope that helps!

Thx @ShopifyDevSup , it works!