Product creation with a single variant that tracks inventory using 2024-04 API

These are how my mutations look like:

mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
product {
id
}
userErrors {
field
message
}
}
}

{
“input”: {
“title”: “Product Title”,
“productType”: “Product X”,
“vendor”: “Vendor X”,
“descriptionHtml”: “Product description”,
“status”: “DRAFT”,
“metafields”: [
{
“namespace”: “custom_fields”,
“key”: “my_custom_field”,
“type”: “single_line_text_field”,
“value”: “Some value..”
}
]
}
}


Then using the productId generated by the previous mutation:

mutation productVariantsBulkCreate($productId: ID!, $strategy: ProductVariantsBulkCreateStrategy, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkCreate(productId: $productId, strategy: $strategy, variants: $variants) {
product {
id
}
userErrors {
field
message
}
}
}

{
“productId”: “gid://shopify/Product/123456789”,
“strategy”: “REMOVE_STANDALONE_VARIANT”,
“variants”: [
{
“inventoryItem”: {
“requiresShipping”: true,
“tracked”: true
},
“inventoryPolicy”: “DENY”,
“inventoryQuantities”: [
{
“availableQuantity”: 1,
“locationId”: “gid://shopify/Location/123456789”
},
{
“availableQuantity”: 0,
“locationId”: “gid://shopify/Location/987654321”
}
],
“sku”: “SKU_ABC”,
“taxable”: true
}
]
}

Hope this helps..