productVariantsBulkUpdate
Requires access scope. Also: The user must have a permission to update product variants.
Updates multiple variants in a single product. This mutation can be called directly or via the bulkOperation.
Arguments
- Anchor to allowPartialUpdatesallow•
Partial Updates BooleanDefault:false When partial updates are allowed, valid variant changes may be persisted even if some of the variants updated have invalid data and cannot be persisted. When partial updates are not allowed, any error will prevent all variants from updating.
- Anchor to mediamedia•
List of new media to be added to the product.
- Anchor to productIdproduct•
Id ID!required The ID of the product associated with the variants to update.
- Anchor to variantsvariants•[Product
Variants requiredBulk Input!]! An array of product variants to update.
Anchor to ProductVariantsBulkUpdatePayload returnsProductVariantsBulkUpdatePayload returns
- Anchor to productproduct•
The updated product object.
- Anchor to productVariantsproduct•
Variants The updated variants.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
- Create and update metafields when updating product variants in bulk
- Modify an existing Product Variant
- Update product variants with option values
- productVariantsBulkUpdate reference
Examples
mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkUpdate(productId: $productId, variants: $variants) {
product {
id
}
productVariants {
id
metafields(first: 2) {
edges {
node {
namespace
key
value
}
}
}
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkUpdate(productId: $productId, variants: $variants) { product { id } productVariants { id metafields(first: 2) { edges { node { namespace key value } } } } userErrors { field message } } }",
"variables": {
"productId": "gid://shopify/Product/20995642",
"variants": [
{
"id": "gid://shopify/ProductVariant/1070325197",
"metafields": [
{
"id": "gid://shopify/Metafield/1069229095",
"value": "SYNTHETIC LEATHER"
},
{
"namespace": "my_fields",
"key": "sole_material",
"value": "RUBBER",
"type": "single_line_text_field"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070325198",
"metafields": [
{
"id": "gid://shopify/Metafield/1069229096",
"value": "SYNTHETIC LEATHER"
},
{
"namespace": "my_fields",
"key": "sole_material",
"value": "CREPE",
"type": "single_line_text_field"
}
]
}
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkUpdate(productId: $productId, variants: $variants) {
product {
id
}
productVariants {
id
metafields(first: 2) {
edges {
node {
namespace
key
value
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"productId": "gid://shopify/Product/20995642",
"variants": [
{
"id": "gid://shopify/ProductVariant/1070325197",
"metafields": [
{
"id": "gid://shopify/Metafield/1069229095",
"value": "SYNTHETIC LEATHER"
},
{
"namespace": "my_fields",
"key": "sole_material",
"value": "RUBBER",
"type": "single_line_text_field"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070325198",
"metafields": [
{
"id": "gid://shopify/Metafield/1069229096",
"value": "SYNTHETIC LEATHER"
},
{
"namespace": "my_fields",
"key": "sole_material",
"value": "CREPE",
"type": "single_line_text_field"
}
]
}
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkUpdate(productId: $productId, variants: $variants) {
product {
id
}
productVariants {
id
metafields(first: 2) {
edges {
node {
namespace
key
value
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"productId": "gid://shopify/Product/20995642",
"variants": [
{
"id": "gid://shopify/ProductVariant/1070325197",
"metafields": [
{
"id": "gid://shopify/Metafield/1069229095",
"value": "SYNTHETIC LEATHER"
},
{
"namespace": "my_fields",
"key": "sole_material",
"value": "RUBBER",
"type": "single_line_text_field"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070325198",
"metafields": [
{
"id": "gid://shopify/Metafield/1069229096",
"value": "SYNTHETIC LEATHER"
},
{
"namespace": "my_fields",
"key": "sole_material",
"value": "CREPE",
"type": "single_line_text_field"
}
]
}
]
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkUpdate(productId: $productId, variants: $variants) {
product {
id
}
productVariants {
id
metafields(first: 2) {
edges {
node {
namespace
key
value
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"productId": "gid://shopify/Product/20995642",
"variants": [{"id"=>"gid://shopify/ProductVariant/1070325197", "metafields"=>[{"id"=>"gid://shopify/Metafield/1069229095", "value"=>"SYNTHETIC LEATHER"}, {"namespace"=>"my_fields", "key"=>"sole_material", "value"=>"RUBBER", "type"=>"single_line_text_field"}]}, {"id"=>"gid://shopify/ProductVariant/1070325198", "metafields"=>[{"id"=>"gid://shopify/Metafield/1069229096", "value"=>"SYNTHETIC LEATHER"}, {"namespace"=>"my_fields", "key"=>"sole_material", "value"=>"CREPE", "type"=>"single_line_text_field"}]}]
}
response = client.query(query: query, variables: variables)