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.

Hey @Kellan-Shopify,

Thanks for the reply. I can see it now. Each product needs to have the app added to their list of publishing sales channel.

Perhaps an image will be helpful to others that come across this topic


Are there any access scopes/configuration that can automatically add my app to the sales channel upon installation? It seems enabling the Storefront API via the partners dashboard did not grant me the results i was looking for.

Hi @Tiwa_Ojo,

I’m glad to hear that you got the issue resolved after publishing the products to your app in the admin.

That is correct that simply enabling the Storefront API wouldn’t resolve this, as the app does need to be a Sales Channel App, and the products need to be published to that channel.

Here’s some documentation on requirements for and guidance on creating Sales Channel Apps.

As for publishing products to the sales channel, if your app is classified as a Sales Channel through the steps in the documentation above, then when new merchants install your app all their existing products will be published to the channel automatically, and new products created after the app is installed should be published to the channel by default, unless the merchant specifies otherwise when creating the product.

If a product is not published to the Sales Channel, then the merchant will need to publish it via the Admin themselves, or you can publish it via the Admin API with a publishablePublish mutation.