Version: 2024-04
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation updateProductVariantMetafields($input: ProductVariantInput!) { productVariantUpdate(input: $input) { productVariant { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }\",\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069228993\",\n \"value\": \"Rubber\"\n }\n ],\n \"id\": \"gid://shopify/ProductVariant/43729076\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation updateProductVariantMetafields($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069228993\",\n \"value\": \"Rubber\"\n }\n ],\n \"id\": \"gid://shopify/ProductVariant/43729076\"\n }\n },\n },\n});\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 updateProductVariantMetafields($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"metafields\": [{\"namespace\"=>\"my_field\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Synthetic Leather\"}, {\"id\"=>\"gid://shopify/Metafield/1069228993\", \"value\"=>\"Rubber\"}],\n \"id\": \"gid://shopify/ProductVariant/43729076\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\n \"metafields\" => [{\"namespace\"=>\"my_field\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Synthetic Leather\"}, {\"id\"=>\"gid://shopify/Metafield/1069228993\", \"value\"=>\"Rubber\"}],\n \"id\" => \"gid://shopify/ProductVariant/43729076\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation updateProductVariantMetafields($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069228993\",\n \"value\": \"Rubber\"\n }\n ],\n \"id\": \"gid://shopify/ProductVariant/43729076\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation updateProductVariantMetafields($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n}"
input: { "input": { "metafields": [ { "namespace": "my_field", "key": "liner_material", "type": "single_line_text_field", "value": "Synthetic Leather" }, { "id": "gid://shopify/Metafield/1069228993", "value": "Rubber" } ], "id": "gid://shopify/ProductVariant/43729076" } }
response: { "data": { "productVariantUpdate": { "productVariant": { "id": "gid://shopify/ProductVariant/43729076", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069228993", "namespace": "my_fields", "key": "sole_material", "value": "Rubber" } }, { "node": { "id": "gid://shopify/Metafield/1069228994", "namespace": "my_field", "key": "liner_material", "value": "Synthetic Leather" } } ] } }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation UpdateProductVariantWithMedia($input: ProductVariantInput!) { productVariantUpdate(input: $input) { product { id } productVariant { id title media(first: 10) { nodes { id alt mediaContentType preview { status } } } } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"options\": [\n \"Yellow\"\n ],\n \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation UpdateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n product {\n id\n }\n productVariant {\n id\n title\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"options\": [\n \"Yellow\"\n ],\n \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n }\n },\n },\n});\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 UpdateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n product {\n id\n }\n productVariant {\n id\n title\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"options\": [\"Yellow\"],\n \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\n \"id\" => \"gid://shopify/ProductVariant/43729076\",\n \"options\" => [\"Yellow\"],\n \"mediaId\" => \"gid://shopify/MediaImage/1041834415\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation UpdateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n product {\n id\n }\n productVariant {\n id\n title\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"options\": [\n \"Yellow\"\n ],\n \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation UpdateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n product {\n id\n }\n productVariant {\n id\n title\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "input": { "id": "gid://shopify/ProductVariant/43729076", "options": [ "Yellow" ], "mediaId": "gid://shopify/MediaImage/1041834415" } }
response: { "data": { "productVariantUpdate": { "product": { "id": "gid://shopify/Product/108828309" }, "productVariant": { "id": "gid://shopify/ProductVariant/43729076", "title": "Yellow", "media": { "nodes": [ { "id": "gid://shopify/ExternalVideo/1041834415", "alt": "This is a video", "mediaContentType": "EXTERNAL_VIDEO", "preview": { "status": "READY" } } ] } }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productVariantUpdate($input: ProductVariantInput!) { productVariantUpdate(input: $input) { productVariant { id title inventoryPolicy inventoryQuantity price compareAtPrice } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"price\": 9.99,\n \"compareAtPrice\": 14.99\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n title\n inventoryPolicy\n inventoryQuantity\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"price\": 9.99,\n \"compareAtPrice\": 14.99\n }\n },\n },\n});\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 productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n title\n inventoryPolicy\n inventoryQuantity\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"price\": 9.99,\n \"compareAtPrice\": 14.99\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\n \"id\" => \"gid://shopify/ProductVariant/43729076\",\n \"price\" => 9.99,\n \"compareAtPrice\" => 14.99,\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n title\n inventoryPolicy\n inventoryQuantity\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/43729076\",\n \"price\": 9.99,\n \"compareAtPrice\": 14.99\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n id\n title\n inventoryPolicy\n inventoryQuantity\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "input": { "id": "gid://shopify/ProductVariant/43729076", "price": 9.99, "compareAtPrice": 14.99 } }
response: { "data": { "productVariantUpdate": { "productVariant": { "id": "gid://shopify/ProductVariant/43729076", "title": "151cm", "inventoryPolicy": "CONTINUE", "inventoryQuantity": 1, "price": "9.99", "compareAtPrice": "14.99" }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation { productVariantUpdate(input: {id: \\\"gid://shopify/ProductVariant/43729076\\\", position: 1, barcode: \\\"1234\\\", weight: 1.5, weightUnit: KILOGRAMS, requiresShipping: true, sku: \\\"EXAMPLE_SKU\\\", taxable: true, taxCode: \\\"\\\", options: [\\\"M\\\"], inventoryItem: {cost: 19.99}}) { productVariant { id legacyResourceId sku barcode weight weightUnit inventoryItem { id legacyResourceId requiresShipping unitCost { amount } } position selectedOptions { name value } product { id title legacyResourceId } } userErrors { field message } } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `mutation {\n productVariantUpdate(input: {id: \"gid://shopify/ProductVariant/43729076\", position: 1, barcode: \"1234\", weight: 1.5, weightUnit: KILOGRAMS, requiresShipping: true, sku: \"EXAMPLE_SKU\", taxable: true, taxCode: \"\", options: [\"M\"], inventoryItem: {cost: 19.99}}) {\n productVariant {\n id\n legacyResourceId\n sku\n barcode\n weight\n weightUnit\n inventoryItem {\n id\n legacyResourceId\n requiresShipping\n unitCost {\n amount\n }\n }\n position\n selectedOptions {\n name\n value\n }\n product {\n id\n title\n legacyResourceId\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n});\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 {\n productVariantUpdate(input: {id: \"gid://shopify/ProductVariant/43729076\", position: 1, barcode: \"1234\", weight: 1.5, weightUnit: KILOGRAMS, requiresShipping: true, sku: \"EXAMPLE_SKU\", taxable: true, taxCode: \"\", options: [\"M\"], inventoryItem: {cost: 19.99}}) {\n productVariant {\n id\n legacyResourceId\n sku\n barcode\n weight\n weightUnit\n inventoryItem {\n id\n legacyResourceId\n requiresShipping\n unitCost {\n amount\n }\n }\n position\n selectedOptions {\n name\n value\n }\n product {\n id\n title\n legacyResourceId\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<query([\"query\" => $query]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation {\n productVariantUpdate(input: {id: \"gid://shopify/ProductVariant/43729076\", position: 1, barcode: \"1234\", weight: 1.5, weightUnit: KILOGRAMS, requiresShipping: true, sku: \"EXAMPLE_SKU\", taxable: true, taxCode: \"\", options: [\"M\"], inventoryItem: {cost: 19.99}}) {\n productVariant {\n id\n legacyResourceId\n sku\n barcode\n weight\n weightUnit\n inventoryItem {\n id\n legacyResourceId\n requiresShipping\n unitCost {\n amount\n }\n }\n position\n selectedOptions {\n name\n value\n }\n product {\n id\n title\n legacyResourceId\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "mutation {\n productVariantUpdate(input: {id: \"gid://shopify/ProductVariant/43729076\", position: 1, barcode: \"1234\", weight: 1.5, weightUnit: KILOGRAMS, requiresShipping: true, sku: \"EXAMPLE_SKU\", taxable: true, taxCode: \"\", options: [\"M\"], inventoryItem: {cost: 19.99}}) {\n productVariant {\n id\n legacyResourceId\n sku\n barcode\n weight\n weightUnit\n inventoryItem {\n id\n legacyResourceId\n requiresShipping\n unitCost {\n amount\n }\n }\n position\n selectedOptions {\n name\n value\n }\n product {\n id\n title\n legacyResourceId\n }\n }\n userErrors {\n field\n message\n }\n }\n}"
input: null
response: { "data": { "productVariantUpdate": { "productVariant": { "id": "gid://shopify/ProductVariant/43729076", "legacyResourceId": "43729076", "sku": "EXAMPLE_SKU", "barcode": "1234", "weight": 1.5, "weightUnit": "KILOGRAMS", "inventoryItem": { "id": "gid://shopify/InventoryItem/43729076", "legacyResourceId": "43729076", "requiresShipping": true, "unitCost": { "amount": "19.99" } }, "position": 1, "selectedOptions": [ { "name": "Title", "value": "M" } ], "product": { "id": "gid://shopify/Product/108828309", "title": "Draft", "legacyResourceId": "108828309" } }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productVariantUpdate($input: ProductVariantInput!) { productVariantUpdate(input: $input) { productVariant { barcode } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/-1\",\n \"barcode\": \"1234_example\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n barcode\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/-1\",\n \"barcode\": \"1234_example\"\n }\n },\n },\n});\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 productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n barcode\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/-1\",\n \"barcode\": \"1234_example\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\n \"id\" => \"gid://shopify/ProductVariant/-1\",\n \"barcode\" => \"1234_example\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n barcode\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"id\": \"gid://shopify/ProductVariant/-1\",\n \"barcode\": \"1234_example\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productVariantUpdate($input: ProductVariantInput!) {\n productVariantUpdate(input: $input) {\n productVariant {\n barcode\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "input": { "id": "gid://shopify/ProductVariant/-1", "barcode": "1234_example" } }
response: { "data": { "productVariantUpdate": { "productVariant": null, "userErrors": [ { "field": [ "id" ], "message": "Product variant does not exist" } ] } } }