product Variants Bulk Updatemutation
mutation
Unstable
Requires
write_products
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
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.
List of new media to be added to the product.
The ID of the product associated with the variants to update.
An array of product variants to update.
Was this section helpful?
ProductVariantsBulkUpdatePayload returns
The updated product object.
The updated variants.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
Hide code
DescriptionCopy
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/unstable/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/1070325053", "metafields": [ { "id": "gid://shopify/Metafield/1069228989", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER", "type": "single_line_text_field" } ] }, { "id": "gid://shopify/ProductVariant/1070325054", "metafields": [ { "id": "gid://shopify/Metafield/1069228990", "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/1070325053", "metafields": [ { "id": "gid://shopify/Metafield/1069228989", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER", "type": "single_line_text_field" } ] }, { "id": "gid://shopify/ProductVariant/1070325054", "metafields": [ { "id": "gid://shopify/Metafield/1069228990", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "CREPE", "type": "single_line_text_field" } ] } ] }, }, ); const data = await response.json();
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/1070325053", "metafields"=>[{"id"=>"gid://shopify/Metafield/1069228989", "value"=>"SYNTHETIC LEATHER"}, {"namespace"=>"my_fields", "key"=>"sole_material", "value"=>"RUBBER", "type"=>"single_line_text_field"}]}, {"id"=>"gid://shopify/ProductVariant/1070325054", "metafields"=>[{"id"=>"gid://shopify/Metafield/1069228990", "value"=>"SYNTHETIC LEATHER"}, {"namespace"=>"my_fields", "key"=>"sole_material", "value"=>"CREPE", "type"=>"single_line_text_field"}]}] } response = client.query(query: query, variables: variables)
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/1070325053", "metafields": [ { "id": "gid://shopify/Metafield/1069228989", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER", "type": "single_line_text_field" } ] }, { "id": "gid://shopify/ProductVariant/1070325054", "metafields": [ { "id": "gid://shopify/Metafield/1069228990", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "CREPE", "type": "single_line_text_field" } ] } ] }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $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/1070325053", "metafields"=>[{"id"=>"gid://shopify/Metafield/1069228989", "value"=>"SYNTHETIC LEATHER"}, {"namespace"=>"my_fields", "key"=>"sole_material", "value"=>"RUBBER", "type"=>"single_line_text_field"}]}, {"id"=>"gid://shopify/ProductVariant/1070325054", "metafields"=>[{"id"=>"gid://shopify/Metafield/1069228990", "value"=>"SYNTHETIC LEATHER"}, {"namespace"=>"my_fields", "key"=>"sole_material", "value"=>"CREPE", "type"=>"single_line_text_field"}]}], ]; $response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "productId": "gid://shopify/Product/20995642", "variants": [ { "id": "gid://shopify/ProductVariant/1070325053", "metafields": [ { "id": "gid://shopify/Metafield/1069228989", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER", "type": "single_line_text_field" } ] }, { "id": "gid://shopify/ProductVariant/1070325054", "metafields": [ { "id": "gid://shopify/Metafield/1069228990", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "CREPE", "type": "single_line_text_field" } ] } ] }
Hide code
Response
JSON
{ "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325053", "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "liner_material", "value": "SYNTHETIC LEATHER" } }, { "node": { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER" } } ] } }, { "id": "gid://shopify/ProductVariant/1070325054", "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "liner_material", "value": "SYNTHETIC LEATHER" } }, { "node": { "namespace": "my_fields", "key": "sole_material", "value": "CREPE" } } ] } } ], "userErrors": [] } }