product Variant Detach Mediamutation
mutation
2024-10latest
Requires write
access scope. Also: The user must have a permission to detach media from product variants.
Detaches media from product variants.
Arguments
Specifies the product to which the variants and media are associated.
A list of pairs of variants and media to be deleted from the variants.
Was this section helpful?
ProductVariantDetachMediaPayload returns
The product associated with the variants and media.
The product variants that were updated.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: productVariantDetachMedia
Query Reference for MUTATION: productVariantDetachMedia
"mutation productVariantDetachMedia($productId: ID!, $variantMedia: [ProductVariantDetachMediaInput!]!) {\n productVariantDetachMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n # Product fields\n }\n productVariants {\n # ProductVariant fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: productVariantDetachMedia
"{\n \"productId\": \"gid://shopify/<objectName>/10079785100\",\n \"variantMedia\": [\n {\n \"mediaIds\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"variantId\": \"gid://shopify/<objectName>/10079785100\"\n }\n ]\n}"
Schema Reference for MUTATION: productVariantDetachMedia
"input ProductVariantDetachMediaInput {\n mediaIds: [ID!]!\n variantId: ID!\n}\n"
Display Examples for MUTATION: productVariantDetachMedia
[ { "example": { "type_name": "productvariantdetachmedia", "title": "Detach a product variant's media from a product", "description": "Detach media of a product from the product's variants", "query_string": "mutation productVariantDetachMedia($productId: ID!, $variantMedia: [ProductVariantDetachMediaInput!]!) {\n productVariantDetachMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n}", "variables": { "productId": "gid://shopify/Product/1072481079", "variantMedia": [ { "mediaIds": [ "gid://shopify/MediaImage/1072273220" ], "variantId": "gid://shopify/ProductVariant/1070325128" }, { "mediaIds": [ "gid://shopify/MediaImage/1072273221" ], "variantId": "gid://shopify/ProductVariant/1070325129" } ] }, "response": { "data": { "productVariantDetachMedia": { "product": { "id": "gid://shopify/Product/1072481079" } } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/product_variant_detach_media_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productVariantDetachMedia($productId: ID!, $variantMedia: [ProductVariantDetachMediaInput!]!) { productVariantDetachMedia(productId: $productId, variantMedia: $variantMedia) { product { id } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481079\",\n \"variantMedia\": [\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273220\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325128\"\n },\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273221\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325129\"\n }\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation productVariantDetachMedia($productId: ID!, $variantMedia: [ProductVariantDetachMediaInput!]!) {\n productVariantDetachMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }`,\n {\n variables: {\n \"productId\": \"gid://shopify/Product/1072481079\",\n \"variantMedia\": [\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273220\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325128\"\n },\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273221\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325129\"\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation productVariantDetachMedia($productId: ID!, $variantMedia: [ProductVariantDetachMediaInput!]!) {\n productVariantDetachMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }\nQUERY\n\nvariables = {\n \"productId\": \"gid://shopify/Product/1072481079\",\n \"variantMedia\": [{\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273220\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325128\"}, {\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273221\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325129\"}]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productVariantDetachMedia($productId: ID!, $variantMedia: [ProductVariantDetachMediaInput!]!) {\n productVariantDetachMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481079\",\n \"variantMedia\": [\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273220\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325128\"\n },\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273221\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325129\"\n }\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation productVariantDetachMedia($productId: ID!, $variantMedia: [ProductVariantDetachMediaInput!]!) {\n productVariantDetachMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }\nQUERY;\n\n$variables = [\n \"productId\" => \"gid://shopify/Product/1072481079\",\n \"variantMedia\" => [{\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273220\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325128\"}, {\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273221\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325129\"}],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "productId", "description": "Specifies the product to which the variants and media are associated.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productId", "argValue": " \"gid://shopify/Product/1072481079\"", "typeKind": "MUTATION" }, { "arg": { "name": "variantMedia", "description": "A list of pairs of variants and media to be deleted from the variants.", "type": { "kind": "INPUT_OBJECT", "name": "ProductVariantDetachMediaInput", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ProductVariantDetachMediaInput!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "variantMedia", "argValue": " [{\"mediaIds\":[\"gid://shopify/MediaImage/1072273220\"],\"variantId\":\"gid://shopify/ProductVariant/1070325128\"},{\"mediaIds\":[\"gid://shopify/MediaImage/1072273221\"],\"variantId\":\"gid://shopify/ProductVariant/1070325129\"}]", "typeKind": "MUTATION" } ] } ]