Version: 2024-07
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation createProductVariantMetafields($input: ProductVariantInput!) { productVariantCreate(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 \"productId\": \"gid://shopify/Product/108828309\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation createProductVariantMetafields($input: ProductVariantInput!) {\n productVariantCreate(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 \"productId\": \"gid://shopify/Product/108828309\"\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 createProductVariantMetafields($input: ProductVariantInput!) {\n productVariantCreate(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\"}],\n \"productId\": \"gid://shopify/Product/108828309\"\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 = <<<QUERY\n mutation createProductVariantMetafields($input: ProductVariantInput!) {\n productVariantCreate(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\n$variables = [\n \"input\" => [\n \"metafields\" => [{\"namespace\"=>\"my_field\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Synthetic Leather\"}],\n \"productId\" => \"gid://shopify/Product/108828309\",\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 createProductVariantMetafields($input: ProductVariantInput!) {\n productVariantCreate(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 \"productId\": \"gid://shopify/Product/108828309\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation createProductVariantMetafields($input: ProductVariantInput!) {\n productVariantCreate(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" } ], "productId": "gid://shopify/Product/108828309" } }
response: { "data": { "productVariantCreate": { "productVariant": { "id": "gid://shopify/ProductVariant/1070325086", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069229040", "namespace": "my_field", "key": "liner_material", "value": "Synthetic Leather" } } ] } }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation CreateProductVariantWithMedia($input: ProductVariantInput!) { productVariantCreate(input: $input) { product { id } productVariant { id title media(first: 10) { nodes { id alt mediaContentType preview { status } } } } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"productId\": \"gid://shopify/Product/108828309\",\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 CreateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantCreate(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 \"productId\": \"gid://shopify/Product/108828309\",\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 CreateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantCreate(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 \"productId\": \"gid://shopify/Product/108828309\",\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 = <<<QUERY\n mutation CreateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantCreate(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\n$variables = [\n \"input\" => [\n \"productId\" => \"gid://shopify/Product/108828309\",\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 CreateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantCreate(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 \"productId\": \"gid://shopify/Product/108828309\",\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 CreateProductVariantWithMedia($input: ProductVariantInput!) {\n productVariantCreate(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": { "productId": "gid://shopify/Product/108828309", "options": [ "Yellow" ], "mediaId": "gid://shopify/MediaImage/1041834415" } }
response: { "data": { "productVariantCreate": { "product": { "id": "gid://shopify/Product/108828309" }, "productVariant": { "id": "gid://shopify/ProductVariant/1070325084", "title": "Yellow", "media": { "nodes": [ { "id": "gid://shopify/ExternalVideo/1041834415", "alt": "This is a video", "mediaContentType": "EXTERNAL_VIDEO", "preview": { "status": "READY" } } ] } }, "userErrors": [] } } }