Add price value to my shop in shopify

Topic summary

A developer is creating products in Shopify via GraphQL mutations but encountering an issue where prices display as ‘0’ despite being set.

Original Implementation:

  • Creates product using productCreate mutation
  • Attempts to add price separately using productVariantCreate mutation
  • Adds product image successfully

Root Cause:
The separate productVariantCreate mutation creates a second variant with the price, but Shopify displays the first (default) variant’s price, which remains unset at ‘0’.

Solution Provided:

  • Include a variants array directly in the initial productCreate mutation with the price value
  • Remove the separate productVariantCreate mutation entirely to avoid creating duplicate variants
  • Keep the image upload code unchanged

Key Technical Detail:
When creating a product without specifying variant details, Shopify automatically generates a default variant with no price. Setting the price during initial creation ensures the default variant has the correct value.

Status: Solution proposed, awaiting confirmation from original poster.

Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

Hi all,

I am creating a product throught my CMS to be added in shopify for the checkout:

const mutation = `
  mutation CreateProduct($product:ProductCreateInput) {
  productCreate(product: $product) {
    product {
      id
      title
      descriptionHtml
      productType
      vendor
      handle     
    }
    userErrors {
      field
      message
    }
  }
}`

  const { data, errors } = await getGraphQLClient().request(mutation, {
    variables: {
      product: {
        title: product.title,
        productType: product.productType,
        descriptionHtml: product.descriptionHtml,
        vendor: 'myShop',
        handle: product.handle,
      },
    },
  })

after i need to add the price, I got this from the ai asistant(after a lot of suffering and pain)

if (data) {
    const priceMutation = `
      mutation CreateVariant($input: ProductVariantInput!) {
        productVariantCreate(input: $input) {
          productVariant {
            id
            price
          }
          userErrors {
            field
            message
          }
        }
      }`
    await getGraphQLClient().request(priceMutation, {
      variables: {
        input: {
          productId: data.productCreate.product.id,
          price: product.price.toString(),
        },
      },
    })

then i add an image

const uploadImageMutation = `
      mutation UploadImage($productId: ID!, $media: [CreateMediaInput!]!) {
        productCreateMedia(productId: $productId, media: $media) {
          media {
            status
            alt
            preview {
              image {
                url
              }
            }
          }
          userErrors {
            field
            message
          }
        }
      }
    `

    await getGraphQLClient().request(uploadImageMutation, {
      variables: {
        productId: data.productCreate.product.id,
        media: [
          {
            originalSource: product.imageUrl,
            mediaContentType: 'IMAGE',
            alt: product.title,
          },
        ],
      },
    })

the problem is that in my shopify store, I am able to see the product created, the image but not the price(it shows ‘0’).

is there something I am missing?

Hi @priceStruggle ,

I am from Mageplaza - Shopify solution expert.

To resolve the issue where the price is showing as ‘0’ in your Shopify store, you need to ensure the price is set during the initial product creation by including variants in the productCreate mutation. Here’s the corrected approach:

1. Include Price in the Initial Product Creation
Add a variants array to your productCreate mutation. This sets the price on the default variant during product creation:

const mutation = `
  mutation CreateProduct($product: ProductCreateInput!) {
    productCreate(input: $product) {
      product {
        id
        title
        variants(first: 10) {
          edges {
            node {
              id
              price
            }
          }
        }
      }
      userErrors {
        field
        message
      }
    }
  }
`;

const { data, errors } = await getGraphQLClient().request(mutation, {
  variables: {
    product: {
      title: product.title,
      productType: product.productType,
      descriptionHtml: product.descriptionHtml,
      vendor: 'myShop',
      handle: product.handle,
      variants: [ // Add variants array here
        {
          price: product.price.toString(), // Set price here
          sku: "YOUR_SKU" // Optional, but recommended
        }
      ]
    }
  }
});

2. Remove the Separate Variant Creation Step
Delete the priceMutation block entirely—it’s redundant and causes conflicts by creating a second variant.

3. Add Images (Unchanged)
Your image upload code is correct and can remain as-is.

Why Your Original Approach Failed:

  • You created a product without a variant price initially.
  • The productVariantCreate mutation added a second variant with the price, but Shopify displays the first variant’s price (which was still 0).
  • The default variant created automatically by Shopify had no price set.

Full Corrected Flow:

// 1. Create product with price in variants
const { data } = await getGraphQLClient().request(mutation, { ... });

// 2. Add image (unchanged)
await getGraphQLClient().request(uploadImageMutation, { ... });

Verification:
After this change, check:

  1. The product has only one variant (the default variant).
  2. The variant’s price is correctly set in the Shopify admin.

This ensures the price displays correctly in your storefront.

Please let me know if it works as expected!

Best regards!