Merchandise does not exist error while adding lines to Cart via cartLinesAdd mutation

Hello,

I am trying to leverage the Storefront API to add/update line items in a users cart via the shopify-app-js package.

I have a valid offline session token with the following scopes: "read_inventory,read_product_listings,read_products,unauthenticated_read_product_listings,unauthenticated_write_checkouts,write_metaobjects,write_orders".

I can’t get past the following error indicating a merchandise does not exist, whereas I can confidently confirm it does via the ProductVariant query.

{
  "field": [
    "lines",
    "0",
    "merchandiseId"
  ],
  "message": "The merchandise with id gid://shopify/ProductVariant/<REDACTED> does not exist."
}

A sample of my source code is as below.

// ... existing code
const shopifyGraphqlClient = new shopifyApiClient.clients.Storefront({ session });
const { data } = await shopifyGraphqlClient.request<AddCartLinesMutation>(
  ADD_CART_LINES_MUTATION_DOCUMENT,
  {
    variables: {
      cartId: cartId,
      lines: cartLines,
    } as AddCartLinesMutationVariables,
  }
);
console.debug(data);

const cart = data?.cartLinesAdd?.cart;
const userErrors = data?.cartLinesAdd?.userErrors;
if (userErrors && userErrors.length > 0) {
  // ...
}

Hi @Tiwa_Ojo,

Are you making the ProductVariant query that is confirming the product exists, from the same Storefront API client?

If you’re using a different app or making the query on the Admin API instead of the Storefront API, it could be possible that the variant exists on the store, but is not published to the Sales Channel App that the Storefront API call is coming from.

If this was the case, the Admin API would return all product on the store, but the Storefront API would only return products that are published to that specific Sales Channel making the API call.

Here’s a Shopify Help Center article with more info on publishing products to different sales channels from the Shopify Admin:

If this doesn’t help resolve the issue for you, can you please provide us with the x-request-id from the HTTP Response Headers of the Request that is returning the error, and we can help look into it further on our end.