Help with productCreate and productVariantsBulkCreate in GraphQL API (2024-07 Version)

Hello Shopify Community,

I am working on creating products using the productCreate and productVariantsBulkCreate mutations in the 2024-07 version of the GraphQL API. However, I am running into an issue where the process doesn’t work as expected.

Problem:- When I use the productCreate mutation, it creates a default variant with a price of 0 and no inventory or quantity, as productOptions doesn’t support variants directly.

  • To add variants, I call productVariantsBulkCreate, passing the necessary options (e.g., price, quantity, SKU, and inventory). While this successfully creates additional variants, it does not override the default variant created by productCreate.

Questions:1. How can I manage this default variant so it doesn’t remain as a placeholder with no proper data?

  1. Is there an alternative approach to create products with variants that bypasses this issue with minimum GraphQL calls?

If anyone has faced a similar issue or knows a better way to handle this, I would appreciate your guidance.

Thank you in advance for your help!

In addition to it, here are mutation I am using for 2024-07,

mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: $productId, variants: $variants) { userErrors { field message } product { id title options { id name values position } } productVariants { id title selectedOptions { name value } compareAtPrice createdAt inventoryPolicy inventoryQuantity position price barcode taxable updatedAt inventoryItem { id measurement { weight { unit value } } requiresShipping sku tracked } } } }

and
mutation CreateProduct($product: ProductInput!, $media: [CreateMediaInput!]!) { productCreate(media: $media, input: $product) { product { id: legacyResourceId productType status vendor title description metafields(first: 250) { edges { node { id key value type namespace } } } options { id name position values optionValues { id name hasVariants } } media(first: 10) { edges { node { id mediaContentType } } } } userErrors { field message } } }

have you tried productVariantUpdate mutation after product creation? and pass first variant from creation response?

1 Like

Also check these mutations

inventoryActivate({

locationId,
inventoryItemId: variant.inventoryItem.id,
available: quantity,

})

inventoryAdjustQuantities({

{
reason: “correction”,
name: “available”,
changes: [
{
delta: quantity,
inventoryItemId: variant.inventoryItem.id,
locationId,
},
],
}})

1 Like

This is an old post now, but this is what ‘[strategy] => REMOVE_STANDALONE_VARIANT’ accomplishes in bulk variant operations.

G