Update product information with GraphQL

Hey, i’m doing an automation on GraphQL… and i’m little stuck on updating a existing product, i need 3 mutations:

  • Update product information (title, descriptionHtml, barcode, SKU).
  • Update product value (unit cost and price)
  • Update product stock (inventory quantity)

IF this first option is not possible, i can do all on one mutation, but i was hoping to make the first option work.

Hey @flavio_ns ,

Thanks for reaching out! No worries at all—here’s how you can update a product using GraphQL in Shopify. You can break it down into three separate mutations:

  1. Update Product Information:

Use productUpdate to update the title, description, barcode, and SKU.

mutation UpdateProductInfo($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
      title
      descriptionHtml
      variants(first: 10) {
        edges {
          node {
            id
            sku
            barcode
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

Variables Example:

{
  "input": {
    "id": "gid://shopify/Product/123456789",
    "title": "New Product Title",
    "descriptionHtml": "

Updated description

",
    "variants": [
      {
        "id": "gid://shopify/ProductVariant/987654321",
        "sku": "NEW-SKU",
        "barcode": "1234567890123"
      }
    ]
  }
}
  1. Update Product Price and Cost:
mutation UpdateProductPrice($input: ProductVariantInput!) {
  productVariantUpdate(input: $input) {
    productVariant {
      id
      price
      inventoryItem {
        unitCost {
          amount
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

Variables Example:

{
  "input": {
    "id": "gid://shopify/ProductVariant/987654321",
    "price": "29.99",
    "inventoryItem": {
      "id": "gid://shopify/InventoryItem/123456789",
      "unitCost": {
        "amount": "15.00"
      }
    }
  }
}
  1. Update Inventory Quantity:

Use inventoryAdjustQuantity to update stock levels.

mutation UpdateInventory($input: InventoryAdjustQuantityInput!) {
  inventoryAdjustQuantity(input: $input) {
    inventoryLevel {
      id
      available
    }
    userErrors {
      field
      message
    }
  }
}

Variables Example:

{
  "input": {
    "inventoryLevelId": "gid://shopify/InventoryLevel/987654321",
    "availableDelta": 10
  }
}

Let me know if you need any more help setting this up in GraphiQL!

If I was able to help you, please don’t forget to Like and mark it as the Solution!
If you’re looking for expert help with customization or coding, I’d be delighted to support you. Please don’t hesitate to reach out via the email in my signature below—I’m here to help bring your vision to life!

Best Regard,
Rajat

Hii @flavio_ns
You can use Product Set Mutation GraphQL Api to update the relevant information.

Thanks, i’ll look into!

Thanks!!!

Hello, how to get this

"id": "gid://shopify/ProductVariant/987654321",

I followed the steps but i’m confused about the ProductVariant specified in the sample. Thank you

@pal3kuno ,

Sure! Please feel free to reach out in my signature below—out with more details about where you’re trying to retrieve the ProductVariant ID. If you’re using Shopify’s GraphQL API, you can fetch it using a query like this:

{
  productVariants(first: 10) {
    edges {
      node {
        id
        title
      }
    }
  }
}

Let me know how I can assist you further!

Hi @rajweb , Thank you for your prompt response. i will give it a try. actually i posted a problem i was wondering if you have any idea on how to accomplish this https://community.shopify.com/topic/2985626 thank you again.

is there way to create Fulfillments by another connector?? if shopify not create any fulfillments, still there any way???