product Variant Append Mediamutation
mutation
2024-10latest
Requires write
access scope. Also: The user must have a permission to append media to variants.
Appends media from a product to variants of the product.
Arguments
Specifies the product associated to the media.
A list of pairs of variants and media to be attached to the variants.
Was this section helpful?
ProductVariantAppendMediaPayload 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: productVariantAppendMedia
Query Reference for MUTATION: productVariantAppendMedia
"mutation productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) {\n productVariantAppendMedia(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: productVariantAppendMedia
"{\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: productVariantAppendMedia
"input ProductVariantAppendMediaInput {\n mediaIds: [ID!]!\n variantId: ID!\n}\n"
Display Examples for MUTATION: productVariantAppendMedia
[ { "example": { "type_name": "productvariantappendmedia", "title": "Append a product's media to variants of the product", "description": "Append media of a product to the product's variants", "query_string": "mutation productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) {\n productVariantAppendMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n}", "variables": { "productId": "gid://shopify/Product/1072481072", "variantMedia": [ { "mediaIds": [ "gid://shopify/MediaImage/1072273216" ], "variantId": "gid://shopify/ProductVariant/1070325119" }, { "mediaIds": [ "gid://shopify/MediaImage/1072273217" ], "variantId": "gid://shopify/ProductVariant/1070325120" } ] }, "response": { "data": { "productVariantAppendMedia": { "product": { "id": "gid://shopify/Product/1072481072" } } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/product_variant_append_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 productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) { productVariantAppendMedia(productId: $productId, variantMedia: $variantMedia) { product { id } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481072\",\n \"variantMedia\": [\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273216\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325119\"\n },\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273217\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325120\"\n }\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) {\n productVariantAppendMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }`,\n {\n variables: {\n \"productId\": \"gid://shopify/Product/1072481072\",\n \"variantMedia\": [\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273216\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325119\"\n },\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273217\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325120\"\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 productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) {\n productVariantAppendMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }\nQUERY\n\nvariables = {\n \"productId\": \"gid://shopify/Product/1072481072\",\n \"variantMedia\": [{\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273216\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325119\"}, {\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273217\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325120\"}]\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 productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) {\n productVariantAppendMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481072\",\n \"variantMedia\": [\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273216\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325119\"\n },\n {\n \"mediaIds\": [\n \"gid://shopify/MediaImage/1072273217\"\n ],\n \"variantId\": \"gid://shopify/ProductVariant/1070325120\"\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 productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) {\n productVariantAppendMedia(productId: $productId, variantMedia: $variantMedia) {\n product {\n id\n }\n }\n }\nQUERY;\n\n$variables = [\n \"productId\" => \"gid://shopify/Product/1072481072\",\n \"variantMedia\" => [{\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273216\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325119\"}, {\"mediaIds\"=>[\"gid://shopify/MediaImage/1072273217\"], \"variantId\"=>\"gid://shopify/ProductVariant/1070325120\"}],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "productId", "description": "Specifies the product associated to the media.", "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/1072481072\"", "typeKind": "MUTATION" }, { "arg": { "name": "variantMedia", "description": "A list of pairs of variants and media to be attached to the variants.", "type": { "kind": "INPUT_OBJECT", "name": "ProductVariantAppendMediaInput", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ProductVariantAppendMediaInput!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "variantMedia", "argValue": " [{\"mediaIds\":[\"gid://shopify/MediaImage/1072273216\"],\"variantId\":\"gid://shopify/ProductVariant/1070325119\"},{\"mediaIds\":[\"gid://shopify/MediaImage/1072273217\"],\"variantId\":\"gid://shopify/ProductVariant/1070325120\"}]", "typeKind": "MUTATION" } ] } ]