Receiving invalid id message after sending cartCreate request via Storefront API

Topic summary

Invalid id error when calling the Storefront API cartCreate mutation in a development shop using Shopify’s sample data. The GraphQL response shows cartCreate: null with error message “invalid id” at path cartCreate.

Context: The user followed Shopify’s Cart walkthrough code and modified merchandiseId. The example uses a ProductVariant GID (gid://shopify/ProductVariant/1), but the user replaced it with a Product GID taken from the Admin URL (gid://shopify/Product/8491982291237).

Key technical points: Storefront API is Shopify’s GraphQL for custom storefronts; cartCreate constructs a cart; merchandiseId is the identifier for the item being added. The code snippet is central to understanding the issue.

Status: No resolution or confirmed fix in the thread. The open question is which ID format/value should be used for merchandiseId and how to correctly obtain it in a development shop.

Action items: None decided; the user is seeking guidance on proper merchandiseId usage (likely a ProductVariant ID) and how to source a valid ID.

Summarized with AI on January 22. AI used: gpt-5.

Hey everyone,

I’m exploring the Shopify Storefront API to decide whether to leverage it in an upcoming build.

I keep receiving an “invalid id” message after sending cartCreate request via Storefront API.

{
	"data": {
		"cartCreate": null
	},
	"errors": [
		{
			"message": "invalid id",
			"locations": [
				{
					"line": 2,
					"column": 3
				}
			],
			"path": [
				"cartCreate"
			]
		}
	]
}

My shop is currently in development mode and uses auto-generated CMS data provided by Shopify.

I’m using the code provided by Shopify in their Building with the Storefront API - Cart walkthrough.

I swapped…

merchandiseId: "gid://shopify/ProductVariant/1"

…with the number I found at the end of the product’s Admin page URL.

merchandiseId: "gid://shopify/Product/8491982291237"

I’m not sure what to do at this point. Any help will be greatly appreciated.

Here’s the entire code from the Building with the Storefront API - Cart walkthrough.

mutation {
  cartCreate(
    input: {
      lines: [
        {
          quantity: 1
          merchandiseId: "gid://shopify/ProductVariant/1"
        }
      ],
      # The information about the buyer that's interacting with the cart.
      buyerIdentity: {
        email: "example@example.com",
        countryCode: CA,
        # An ordered set of delivery addresses associated with the buyer that's interacting with the cart. The rank of the preferences is determined by the order of the addresses in the array. You can use preferences to populate relevant fields in the checkout flow.
        deliveryAddressPreferences: {
          deliveryAddress: {
            address1: "150 Elgin Street",
            address2: "8th Floor",
            city: "Ottawa",
            province: "Ontario",
            country: "CA",
            zip: "K2P 1L4"
          },
        }
      }
      attributes: {
        key: "cart_attribute",
        value: "This is a cart attribute"
      }
    }
  ) {
    cart {
      id
      createdAt
      updatedAt
      lines(first: 10) {
        edges {
          node {
            id
            merchandise {
              ... on ProductVariant {
                id
              }
            }
          }
        }
      }
      buyerIdentity {
        deliveryAddressPreferences {
          __typename
        }
      }
      attributes {
        key
        value
      }
      # The estimated total cost of all merchandise that the customer will pay at checkout.
      cost {
        totalAmount {
          amount
          currencyCode
        }
        # The estimated amount, before taxes and discounts, for the customer to pay at checkout.
        subtotalAmount {
          amount
          currencyCode
        }
        # The estimated tax amount for the customer to pay at checkout.
        totalTaxAmount {
          amount
          currencyCode
        }
        # The estimated duty amount for the customer to pay at checkout.
        totalDutyAmount {
          amount
          currencyCode
        }
      }
    }
  }
}