GraphQL Storefront API For Discount On Checkout CheckoutUserErrors Array Is Empty

GraphQL Storefront API For Discount On Checkout CheckoutUserErrors Array Is Empty

gautam9176
Shopify Partner
4 0 2

If code doesn't satisfy the conditions then checkoutUserErrors array should not be empty.

mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {
  checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {
    checkout {
      discountApplications(first: 10) {        
        edges {
          node {
            allocationMethod
            targetSelection
            targetType
            value
          }
        }
      }
      lineItems(first: 10) {
          edges {
          node {
            title
            quantity
            unitPrice{
                amount
            }
            variant{
                id
            }
          }
        }
      }
      webUrl
      totalPrice{
          amount
          currencyCode
        }
        shippingLine{
            title
        }
    }
    checkoutUserErrors 
    {
        field
        message
        code
        __typename
        ... on DisplayableError {
            field
            message
        }
    }
  }
}


{
  "checkoutId": "gid://shopify/Checkout/8c149ab96939ec3fe7791012c2fb8739?key=3725795c2f5e0fbd31c8f77e339164fd",
  "discountCode": "Test123"
}
{
    "data": {
        "checkoutDiscountCodeApplyV2": {
            "checkout": {
                "discountApplications": {
                    "edges": []
                },
                "lineItems": {
                    "edges": [
                        {
                            "node": {
                                "title": "\"Целувката\" И  \"Девицата\" На Густав Климт - Арт Пъзел 2Х1000 Части",
                                "quantity": 1,
                                "unitPrice": null,
                                "variant": {
                                    "id": "gid://shopify/ProductVariant/46702843789649"
                                }
                            }
                        }
                    ]
                },
                "webUrl": "https://bebemama-com.myshopify.com/25718685778/checkouts/8c149ab96939ec3fe7791012c2fb8739?key=3725795c2f5e0fbd31c8f77e339164fd",
                "totalPrice": {
                    "amount": "39.9",
                    "currencyCode": "BGN"
                },
                "shippingLine": null
            },
            "checkoutUserErrors": []
        }
    }
}

 

Reply 1 (1)

Liam
Shopify Staff
2862 313 813

 

Hi Gautam9176,

 

Looking at this it seems that no errors occurred during the mutation execution. This could mean that the discount code "Test123" is valid but may not have any applicable discounts associated with it.

 

In case the discount code does not satisfy the conditions for the discount, the "checkoutUserErrors" array should indeed contain error messages, but in this case, it is empty.

 

You should ensure that your"Test123" discount code is set up correctly with the applicable conditions in your Shopify admin. If the problem persists, you may need to contact Shopify support directly to look into this further. 

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog