[bug] using cartCreate when adding lines to cart

Solved

[bug] using cartCreate when adding lines to cart

MD-MGNP
Visitor
3 1 0

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"
    }
  }
}

 

 

My Drugs - MGNP
Using Shopify Hydrogen + Oxygen (latest versions)
Accepted Solution (1)

MD-MGNP
Visitor
3 1 0

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

My Drugs - MGNP
Using Shopify Hydrogen + Oxygen (latest versions)

View solution in original post

Reply 1 (1)

MD-MGNP
Visitor
3 1 0

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

My Drugs - MGNP
Using Shopify Hydrogen + Oxygen (latest versions)