How to set price , inventory and variants in the productCreate Admin GraphQl API?

Topic summary

Developers are struggling to set price, inventory, and variants when using Shopify’s latest productCreate Admin GraphQL API (2024-04+). The variants field present in earlier versions (2024-01) appears to have been removed or restructured.

Core Issue:

  • The latest API lacks direct fields for price, inventory, and variants in productCreate
  • Attempting to use productVariantCreate for simple products (without options) returns an error: “The variant ‘Default Title’ already exists”

Working Solution (confirmed by multiple users):

  1. First create the base product using productCreate mutation
  2. Then use productVariantsBulkCreate mutation with strategy: "REMOVE_STANDALONE_VARIANT" to set price, SKU, and inventory
  3. This approach works for both simple products and products with variants

Code snippet provided:

productVariantsBulkCreate(
  productId: [returned-product-id],
  strategy: "REMOVE_STANDALONE_VARIANT",
  variants: [{ inventoryItem: { sku: "..." }, price: "..." }]
)

Remaining Questions:

  • How to add images, weight, and stock levels
  • How to set cost price and product categories
  • How to handle products sold by measurement units (e.g., 150ml per unit)
Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

I aim to utilize the most recent version of the Shopify API, specifically the productCreate endpoint, to generate both simple and variant products. However, I’ve encountered an absence of fields for defining crucial attributes such as price, inventory, or variants in the latest API version.

Interestingly, upon inspection, I noticed that the variants field is present in the 2024-01 API version. Given the possibility of these features being deprecated in newer versions, I’m curious about potential substitutes for the variants field in the latest API iteration.

1 Like

In the latest versions of the Shopify Admin GraphQL API, including versions beyond 2024-01, some fields and methods for creating and managing product variants, pricing, and inventory may have been restructured or moved to different endpoints or mutations. Here’s how you can manage products with variants, pricing, and inventory using the most recent Shopify API.

1. Creating a Product with Variants

In the latest API versions, creating a product and its variants may require a more structured approach, potentially involving multiple steps or different mutations. Below is an approach using the productCreate mutation followed by the productVariantCreate mutation to set up variants:

Step 1: Create the Product

First, create a base product without variants using the productCreate mutation:

mutation {
  productCreate(input: {
    title: "Example Product"
    descriptionHtml: "**Good product!**"
    productType: "Clothing"
    vendor: "Example Vendor"
  }) {
    product {
      id
      title
    }
    userErrors {
      field
      message
    }
  }
}
1 Like

What about the default variant? for example if i want to create a simple product in shopify (without any variants) how can i set the price, inventory for them? is there any API ?

NOTE: if i use the productVariantCreate API to set price and inventory for simple products i got below error from graphql api.. it is working fine for variants.. so how can i set price, inventory for simple products (product without options) ? please help..

"userErrors": [
                {
                    "field": null,
                    "message": "The variant 'Default Title' already exists."
                }
            ]
2 Likes

Hello I am stuck on same situation, they don’t give us documentation for how to add price in product

https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productCreate

If you resolve this please share you answer

2 Likes

After a Long struggle I found a solution ufff, I don’t know why shopify API it’s too hard, make it simple add regular and compare price, any way here is solution

const productCreatePrice = await client.query({
                  data:{
                    query: mutation productVariantsBulkCreate($productId: ID!,$strategy: ProductVariantsBulkCreateStrategy, $variants: [ProductVariantsBulkInput!]!) {
    productVariantsBulkCreate(productId: $productId,strategy: $strategy, variants: $variants) {
      product {
        id
      }
      productVariants {
        id
        metafields(first: 1) {
          edges {
            node {
              namespace
              key
              value
            }
          }
        }
      }
      userErrors {
        field
        message
      }
    }
  },
                    variables:{
                      productId: '<--ADD-RETURN-PRODUCT-ID-HERE-->',
                      strategy: "REMOVE_STANDALONE_VARIANT",
                      variants: [
                        {
                          inventoryItem: {
                            sku: `[IS UP TO YOU]`
                          },
                          inventoryPolicy: "CONTINUE",
                          price: '<--HERE-PRICE-->'
                        }
                      ]
                    }
                  }
                })
3 Likes

Thanks so much for this - I spent way too long trying to work this out before finding your solution. Working well for me. Thanks again.

2 Likes

welcome same I spent a lot of time on this.

1 Like

I’m currently stuck in the same situation. Were you able to find a solution to include the price, inventory, and SKU for a product without adding any variants? If so, I’d greatly appreciate your help! (For more refrence: https://community.shopify.com/topic/2964382 )

1 Like

Stuck on the same stuff, i need to create a product with default price, SKU and stock… not variants, inventories and other hard stuff.

Thanks alot! Did you find a way to upload imagem, weight and stock? My brain is literally melting.

PS: I create the product, price and etcetera with this method but i can’t place it on the cart, it gives error finding the variant.

Create the Product: The first operation in your code is creating the product in Shopify. You use the productCreate mutation to create the product with the required details such as the title, vendor, and status (which is set to “DRAFT” in your example).

const productCreateMutation = gql`
  mutation productCreate($product: ProductCreateInput!) {
    productCreate(product: $product) {
      product { id title status }
      userErrors { field message }
    }
  }
`;

// Example product input
const productInput = {
  title: product.Description || "Untitled Product",
  vendor: product.SupplierCode || "Unknown Vendor",
  status: "DRAFT", // Product is created in draft mode
  tags: ["importLStoSHOP"],
};

const productCreateResponse = await client.request(productCreateMutation, { product: productInput });

Above step creates the product but does not include any price or variant details.

Now, Create the Variant and Set the Price: Once the product is created, you can add a variant to it using the productVariantsBulkCreate mutation. This is where you set the price, SKU, barcode, and other variant-specific information.

const productVariantsBulkCreateMutation = gql`
  mutation productVariantsBulkCreate($productId: ID!, $strategy: ProductVariantsBulkCreateStrategy, $variants: [ProductVariantsBulkInput!]!) {
    productVariantsBulkCreate(productId: $productId, strategy: $strategy, variants: $variants) {
      product { id }
      productVariants { id inventoryItem { id } }
      userErrors { field message }
    }
  }
`;

// Example variant data
const variants = [{
  inventoryItem: { sku: product.PartNumber || "UNKNOWN-SKU" },
  price: product.CurrentActivePrice || 0.0, // Set the price here
  barcode: product.UPC || null,
}];

const variantsResponse = await client.request(productVariantsBulkCreateMutation, {
  productId,
  strategy: "REMOVE_STANDALONE_VARIANT",
  variants,
});

Above step creates the variant for the product and includes the price for that variant.

1 Like

Ok, i thing i got it! I’m doing via GraphiQL/N8N… now i just need to add images and video IF the JSON have (the URL), and weight.

PS: If possible i would love to add ‘cost_price’ and ‘category’ if possible.
PSS: I can i can sell my product by measures? Like, if i my product sell 150ml per unit price.