Cart: How to retrieve discount amount?

I create a cart with a working discount code, and it successfully updates the cost according to the discount applied:

mutation CartCreate($input: CartInput!) {
		cartCreate(input: $input) {
			cart {
				id
				discountCodes {
					code
					applicable
				}
				discountAllocations {
					discountedAmount {
						amount
					}
				}
				cost {
					totalAmount {
						amount
					}
				}
			}
		}
	}

But when I try to retrieve the discounted amount with “discountAllocations” following the API, it gives me an empty object.

{
  "data": {
    "cart": {
      "id": "gid://shopify/Cart/2bbbd6d5e115b0f661a3642d1521efb2",
      "discountAllocations": []
    }
  }
}
1 Like

Solved it by adding discountAllocation inside lines, not the cart directly, as some discounts are applied to the whole cart, and others are applied to the line items.

lines(first: 100) {
        edges {
          node {
            id
            quantity
            discountAllocations {
              discountedAmount {
                amount
                currencyCode
              }
            }