Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
When I use the mutation cartCreate to update the lines of the cart I receive the error below regarding the "merchandiseId" that I'm passing, except that the ID is actually the correct one since I also use them to fetch products.
As I saw in the documentation:
Ex. gid://shopify/Product/10079785100
I don't even know if it's actually the "merchandiseId" or some other one as it's not specified by the error response.
The GraphQL request:
mutation cartCreate($input: CartInput!, $country: CountryCode = ZZ, $language: LanguageCode) @inContext(country: $country, language: $language) { cartCreate(input: $input) { cart { ...CartApiMutation checkoutUrl } userErrors { ...CartApiError } } } fragment CartApiMutation on Cart { id totalQuantity } fragment CartApiError on CartUserError { message field code }
The variables:
{ "input": { "lines": [ { "merchandiseId": "gid://shopify/Product/<something>" } ], "buyerIdentity": {} }, "country": "US", "language": "EN" }
The error that I receive:
{ "data": { "cartCreate": null }, "errors": [ { "message": "invalid id", "path": [ "cartCreate" ], "locations": [] } ], "extensions": { "context": { "country": "US", "language": "EN" } } }
Solved! Go to the solution
This is an accepted solution.
It's NOT a bug.
I was using the wrong id, the correct one (that you can find here) is the id of the selected ProductVariant.
When you fetch the Product you can find the id under Product.variants.nodes[<index>].id
This is an accepted solution.
It's NOT a bug.
I was using the wrong id, the correct one (that you can find here) is the id of the selected ProductVariant.
When you fetch the Product you can find the id under Product.variants.nodes[<index>].id