Hello,
I’m trying to create products in draft mode in my Shopify store using the productCreate mutation. Below is the mutation I am using, along with the input for creating the product:
const mutation = gql`
mutation productCreate($product: ProductCreateInput) {
productCreate(product: $product) {
product {
id
title
status
}
userErrors {
field
message
}
}
}
`;
Input (currently without variants):
const productInput = {
title: product.Description || "Untitled Product",
vendor: product.SupplierCode || "Unknown Vendor",
status: "DRAFT",
// variants: [
// {
// sku: product.PartNumber || "UNKNOWN-SKU",
// price: product.CurrentActivePrice || 0.0,
// barcode: product.UPC || null,
// },
// ],
tags: ["importLStoSHOP"],
};
I am currently able to successfully create the product with only the title, vendor, status, and tags. However, when I try to include the variants section (which I have commented out in the code), I encounter the following error:
Variable $product of type ProductCreateInput was provided an invalid value for variants (Field is not defined on ProductCreateInput)
Question:
- How can I add fields (such as price, cost, SKU, barcode, inventory quantity, and track inventory as true) to the product input in the mutation?
- What changes should I make to properly define and include the variants field in the product creation process?
Any help or suggestions would be greatly appreciated as I’m still learning GraphQL.
Thank you!