CartCreate: Cart object always returns null with no UserErrors listed

Topic summary

Storefront API cartCreate returned a null cart with empty userErrors when attempting to add a product variant via lines. The same mutation worked in Shopify’s GraphQL explorer with a sample variant, and removing lines returned a valid cart, pointing to line-item configuration.

Root cause and fix:

  • For subscription products, each line must include sellingPlanId alongside merchandiseId. Without it, the API may return null with no error. An npm checkout library exposed the hidden error: “Selling plan must exist.”
  • Working cartInput example: lines[{ merchandiseId, sellingPlanId }].

Follow-up details:

  • Question: Is sellingPlanId the same across products? Reply: Selling plans aren’t strictly bound to a product; a given selling plan retains the same ID across products. Suggested verification by adding a purchase option to a dummy product and comparing IDs.
  • Open question: How to retrieve a product’s selling plans via API is uncertain; a separate thread was suggested.

Status:

  • Original cart creation issue: resolved by including sellingPlanId for subscription items.
  • Outstanding: Best practice/API method to programmatically obtain sellingPlanId for products.
Summarized with AI on December 29. AI used: gpt-5.

Hello. I tried using the CartCreate function from the Storefront API, but I keep receiving a null cart with no errors listed.

Query:

mutation createCart($cartInput: CartInput) {
  cartCreate(
    input: $cartInput
  ) {
    cart {
      id
      createdAt
      updatedAt
      checkoutUrl
    }
    userErrors {
      field
      message
    }
  }
}

Variable (note: {{VARIANTID}} was hardcoded in actual scenario):

{
  "cartInput": {
    "buyerIdentity": null,
    "lines": [
      {
        "merchandiseId": "gid://shopify/ProductVariant/{{VARIANTID}}",
        "quantity": 1
      }
    ]
  }
}

Response:

{
   cart: null
   userErrors: []
}

I tried changing the {{VARIANTID}} to an invalid one, and I finally got an error saying the merchantId doesn’t exist, so I assume my query was valid after all.

I used the same query on Shopify’s GraphQL explorer while replacing {{VARIANTID}} with a sample id provided in the explorer, and the cart was not null:

{
  "data": {
    "cartCreate": {
      "cart": {
        "id": "gid://shopify/Cart/Z2NwLWFzaWEtc291dGhlYXN0MTowMUhYRVBTTjRBSlhRQVMyTjBQRFBQTVcxSA",
        "createdAt": "2024-05-09T12:56:04Z",
        "updatedAt": "2024-05-09T12:56:04Z",
        "checkoutUrl": "https://graphql.myshopify.com/cart/c/Z2NwLWFzaWEtc291dGhlYXN0MTowMUhYRVBTTjRBSlhRQVMyTjBQRFBQTVcxSA?key=d37b4857f88b1e032cf7a3547432d1fd"
      },
      "userErrors": []
    }
  }
}

Is there a configuration I’m missing here or in the store itself?

1 Like

Same here i’ve got no cart object at all, any updates yet?

I have none so far. I do think the issue lies within the configuration of the product I’ve set up in the product variant since removing the “lines” properly shows the Cart object on the response along with the properties I needed.

If your product is a subscription for your service app, you also need to include the Selling Plan Id.

In this case, the variables should be:

{
    "cartInput": {
        "lines": [
            {
                "merchandiseId": "gid://shopify/ProductVariant/{{VARIANTID}}",
                "sellingPlanId": "gid://shopify/SellingPlan/{{SELLINGPLANID}}"
            }
        ]
    }
}

How I knew about this: there’s no error message for this on the API, so I tried using the npm library for shopify that creates a checkout wherein I got the error “Selling plan must exist”.

How I found the selling plan Id

1 Like

Thank you for sharing! I will give it a try.

I’ve got a question, will this selling plan id be the same for all products?

I was just wondering if we could get the selling plan id via product object or something, that way it’d be better when the plan id get changed later.

I’ve got a question, will this selling plan id be the same for all products?

As far as I’ve seen, selling plans are not strictly bound to a product, so a particular selling plan must have the same id across all products. We could confirm that by creating a dummy product and adding a purchase option, and comparing the two products (original product and dummy product) in your online store by checking the selling plan Id.

I was just wondering if we could get the selling plan id via product object or something, that way it’d be better when the plan id get changed later.

I’m not quite sure yet if the API’s capable of retrieving the selling plans being used in a product. Probably best to make a separate thread for this topic.

1 Like