Retrieve the checkoutId to use it in checkoutDiscountCodeApplyV2

Topic summary

Main issue: How to obtain checkoutId required by the checkoutDiscountCodeApplyV2 mutation.

Key guidance:

  • Retrieve checkoutId from the response of the checkoutCreate mutation (it returns the newly created checkout’s ID).
  • Alternatively, query the customer’s lastIncompleteCheckout field to get the most recent unfinished checkout, which includes its ID.

Outcome: Clear methods provided to fetch checkoutId either at checkout creation or from a customer’s pending checkout. No disagreements or unresolved questions; the thread appears resolved.

Summarized with AI on January 15. AI used: gpt-5.

How can I know the checkoutId to use it in checkoutDiscountCodeApplyV2? In the documentation the mutation has this form:

mutation checkoutDiscountCodeApplyV2($checkoutId: ID!, $discountCode: String!) {
  checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {
    checkout {
      # Checkout fields
    }
    checkoutUserErrors {
      # CheckoutUserError fields
    }
  }
}

With these variables:

{
  "checkoutId": "",
  "discountCode": ""
}

Where do I find the checkoutId?

Hey @jesusaguiar , that’s a great question.

You can get the checkout ID from the response of the createCheckout mutation https://shopify.dev/docs/api/storefront/2023-10/mutations/checkoutCreate

Another place is to query the customer for last incomplete checkout https://shopify.dev/docs/api/storefront/2023-10/objects/Customer#field-customer-lastincompletecheckout

Hope that helps.

  • Kyle G.