Retrieve the checkoutId to use it in checkoutDiscountCodeApplyV2

jesusaguiar
Shopify Partner
1 0 0

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?

 

Reply 1 (1)
ShopifyDevSup
Shopify Staff
Shopify Staff
1202 190 420

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-lastincompletechecko... 

 

Hope that helps. 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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