Retrieve the checkoutId to use it in checkoutDiscountCodeApplyV2

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.