I’m using productVariantsBulkUpdate graphql mutation to update variant pricing and metafields. But, the metafields update is failing. If I pass id and value for the metafield definition, I receive errors stating I need to include key, namespace, etc.. (X can’t be blank or X is too short).
If I include everything (id, namespace, key, name, type), I receive a "
Key must be unique within this namespace on this resource" error.
My first inclination is that the input is somehow assuming that I’m attempting to create a new metafield, even if an id is passed.
My sample mutation:
mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkUpdate(productId: $productId, variants: $variants) {
product {
id
}
productVariants {
id,
sku
price
metafields(first: 10) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
field
message
}
}
}
Sample input (actual ids removed):
{
"productId": "gid://shopify/Product/<id>",
"variants": [
{
"id": "gid://shopify/ProductVariant/<variant_id>",
"price": "275",
"metafields": [
{
"id": "gid://shopify/Metafield/<field_1>",
"value": "266.75"
},
{
"id": "gid://shopify/Metafield/<field_2>",
"value": "265.29"
},
{
"id": "gid://shopify/Metafield/<field_3>",
"value": "263.92"
},
{
"id": "gid://shopify/Metafield/<field_4>",
"value": "262.4"
},
{
"id": "gid://shopify/Metafield/<field_5>",
"value": "261.14"
}
]
},
{
"id": "gid://shopify/ProductVariant/<variant_id>",
"price": "15",
"metafields": [
{
"id": "gid://shopify/Metafield/<field_1>",
"value": "14.55"
},
{
"id": "gid://shopify/Metafield/<field_2>",
"value": "14.47"
},
{
"id": "gid://shopify/Metafield/<field_3>",
"value": "14.4"
},
{
"id": "gid://shopify/Metafield/<field_4>",
"value": "14.31"
},
{
"id": "gid://shopify/Metafield/<field_5>",
"value": "14.24"
}
]
}
]
}
If I remove the metafields altogether, the price bulk updates work fine.