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 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 = <<[\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-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productVariantCreate($input: ProductVariantInput!) { productVariantCreate(input: $input) { product { id title } productVariant { createdAt displayName id inventoryItem { unitCost { amount } tracked } inventoryPolicy inventoryQuantity price product { id } title } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/-1\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/-1\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\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 productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/-1\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\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 \"inventoryItem\" => [\n \"cost\" => 50,\n \"tracked\" => true,\n ],\n \"inventoryPolicy\" => \"DENY\",\n \"inventoryQuantities\" => [\n \"availableQuantity\" => 25,\n \"locationId\" => \"gid://shopify/Location/346779380\",\n ],\n \"price\" => 114.99,\n \"productId\" => \"gid://shopify/Product/-1\",\n \"requiresShipping\" => true,\n \"options\" => \"Holographic\",\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 productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/-1\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "input": { "inventoryItem": { "cost": 50, "tracked": true }, "inventoryPolicy": "DENY", "inventoryQuantities": { "availableQuantity": 25, "locationId": "gid://shopify/Location/346779380" }, "price": 114.99, "productId": "gid://shopify/Product/-1", "requiresShipping": true, "options": "Holographic" } }
response: { "data": { "productVariantCreate": { "product": null, "productVariant": null, "userErrors": [ { "field": [ "productId" ], "message": "Product does not exist" } ] } } }
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 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 = <<[\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": [] } } }
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 productVariantCreate($input: ProductVariantInput!) { productVariantCreate(input: $input) { product { id title } productVariant { createdAt displayName id inventoryItem { unitCost { amount } tracked } inventoryPolicy inventoryQuantity price product { id } title } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/108828309\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/108828309\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\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 productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/108828309\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\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 \"inventoryItem\" => [\n \"cost\" => 50,\n \"tracked\" => true,\n ],\n \"inventoryPolicy\" => \"DENY\",\n \"inventoryQuantities\" => [\n \"availableQuantity\" => 25,\n \"locationId\" => \"gid://shopify/Location/346779380\",\n ],\n \"price\" => 114.99,\n \"productId\" => \"gid://shopify/Product/108828309\",\n \"requiresShipping\" => true,\n \"options\" => \"Holographic\",\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 productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"inventoryItem\": {\n \"cost\": 50,\n \"tracked\": true\n },\n \"inventoryPolicy\": \"DENY\",\n \"inventoryQuantities\": {\n \"availableQuantity\": 25,\n \"locationId\": \"gid://shopify/Location/346779380\"\n },\n \"price\": 114.99,\n \"productId\": \"gid://shopify/Product/108828309\",\n \"requiresShipping\": true,\n \"options\": \"Holographic\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productVariantCreate($input: ProductVariantInput!) {\n productVariantCreate(input: $input) {\n product {\n id\n title\n }\n productVariant {\n createdAt\n displayName\n id\n inventoryItem {\n unitCost {\n amount\n }\n tracked\n }\n inventoryPolicy\n inventoryQuantity\n price\n product {\n id\n }\n title\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "input": { "inventoryItem": { "cost": 50, "tracked": true }, "inventoryPolicy": "DENY", "inventoryQuantities": { "availableQuantity": 25, "locationId": "gid://shopify/Location/346779380" }, "price": 114.99, "productId": "gid://shopify/Product/108828309", "requiresShipping": true, "options": "Holographic" } }
response: { "data": { "productVariantCreate": { "product": { "id": "gid://shopify/Product/108828309", "title": "Draft" }, "productVariant": { "createdAt": "2024-09-12T01:09:07Z", "displayName": "Draft - Holographic", "id": "gid://shopify/ProductVariant/1070325085", "inventoryItem": { "unitCost": { "amount": "50.0" }, "tracked": true }, "inventoryPolicy": "DENY", "inventoryQuantity": 25, "price": "114.99", "product": { "id": "gid://shopify/Product/108828309" }, "title": "Holographic" }, "userErrors": [] } } }