I want to apply discount coupon code to the cart page, I am trying to use the storefront API cartDiscountCodesUpdate which expect the cart id. How can I get this cart id. Here is what I tried. I have created the webhook cart/create which has payload id in the form of string something like '1eef2aa2c2b2e889ec325db72f0877ec'.
Then I tried calling this id which I got from cart/create response in storefront API cartDiscountCodesUpdate like:
mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]) {
cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
cart {
id
}
userErrors {
field
message
}
}
}
Query Varialbe: { "cartId": "gid://shopify/Cart/1eef2aa2c2b2e889ec325db72f0877ec", "discountCodes": [ "64J1ZQMBN9W5" ] }
But its response with below error. I think its the issue with incorrect cart id. Can anyone help me how to get cart id after the cart is created?
Response from cartDiscountCodesUpdate storefront API.
{
"data": {
"cartDiscountCodesUpdate": {
"cart": null,
"userErrors": [
{
"field": [
"cartId"
],
"message": "The specified cart does not exist."
}
]
}
}
}