product Options Createmutation
mutation
2025-01release candidate
Requires
write_products
access scope. Also: The user must have a permission to create product variants.
Creates options on a product.
Arguments
Options to add to the product.
The ID of the product to update.
The strategy defines which behavior the mutation should observe regarding variants. If not provided or set to null, the strategy
L
will be used.E A V E _A S _I S
Was this section helpful?
ProductOptionsCreatePayload returns
The updated product object.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
Hide code
DescriptionCopy
mutation createOptions($productId: ID!, $options: [OptionCreateInput!]!) { productOptionsCreate(productId: $productId, options: $options) { userErrors { field message code } product { options { name linkedMetafield { namespace key } optionValues { name linkedMetafieldValue } } } } }
curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation createOptions($productId: ID!, $options: [OptionCreateInput!]!) { productOptionsCreate(productId: $productId, options: $options) { userErrors { field message code } product { options { name linkedMetafield { namespace key } optionValues { name linkedMetafieldValue } } } } }", "variables": { "productId": "gid://shopify/Product/1072481047", "options": [ { "name": "Color", "linkedMetafield": { "namespace": "shopify", "key": "color-pattern", "values": [ "gid://shopify/Metaobject/971662467", "gid://shopify/Metaobject/971662468", "gid://shopify/Metaobject/971662469" ] } } ] } }'
const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation createOptions($productId: ID!, $options: [OptionCreateInput!]!) { productOptionsCreate(productId: $productId, options: $options) { userErrors { field message code } product { options { name linkedMetafield { namespace key } optionValues { name linkedMetafieldValue } } } } }`, { variables: { "productId": "gid://shopify/Product/1072481047", "options": [ { "name": "Color", "linkedMetafield": { "namespace": "shopify", "key": "color-pattern", "values": [ "gid://shopify/Metaobject/971662467", "gid://shopify/Metaobject/971662468", "gid://shopify/Metaobject/971662469" ] } } ] }, }, ); const data = await response.json();
session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation createOptions($productId: ID!, $options: [OptionCreateInput!]!) { productOptionsCreate(productId: $productId, options: $options) { userErrors { field message code } product { options { name linkedMetafield { namespace key } optionValues { name linkedMetafieldValue } } } } } QUERY variables = { "productId": "gid://shopify/Product/1072481047", "options": [{"name"=>"Color", "linkedMetafield"=>{"namespace"=>"shopify", "key"=>"color-pattern", "values"=>["gid://shopify/Metaobject/971662467", "gid://shopify/Metaobject/971662468", "gid://shopify/Metaobject/971662469"]}}] } response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation createOptions($productId: ID!, $options: [OptionCreateInput!]!) { productOptionsCreate(productId: $productId, options: $options) { userErrors { field message code } product { options { name linkedMetafield { namespace key } optionValues { name linkedMetafieldValue } } } } }`, "variables": { "productId": "gid://shopify/Product/1072481047", "options": [ { "name": "Color", "linkedMetafield": { "namespace": "shopify", "key": "color-pattern", "values": [ "gid://shopify/Metaobject/971662467", "gid://shopify/Metaobject/971662468", "gid://shopify/Metaobject/971662469" ] } } ] }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $query = <<<QUERY mutation createOptions($productId: ID!, $options: [OptionCreateInput!]!) { productOptionsCreate(productId: $productId, options: $options) { userErrors { field message code } product { options { name linkedMetafield { namespace key } optionValues { name linkedMetafieldValue } } } } } QUERY; $variables = [ "productId" => "gid://shopify/Product/1072481047", "options" => [{"name"=>"Color", "linkedMetafield"=>{"namespace"=>"shopify", "key"=>"color-pattern", "values"=>["gid://shopify/Metaobject/971662467", "gid://shopify/Metaobject/971662468", "gid://shopify/Metaobject/971662469"]}}], ]; $response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "productId": "gid://shopify/Product/1072481047", "options": [ { "name": "Color", "linkedMetafield": { "namespace": "shopify", "key": "color-pattern", "values": [ "gid://shopify/Metaobject/971662467", "gid://shopify/Metaobject/971662468", "gid://shopify/Metaobject/971662469" ] } } ] }
Hide code
Response
JSON
{ "productOptionsCreate": { "userErrors": [], "product": { "options": [ { "name": "Color", "linkedMetafield": { "namespace": "shopify", "key": "color-pattern" }, "optionValues": [ { "name": "Red", "linkedMetafieldValue": "gid://shopify/Metaobject/971662467" }, { "name": "Blue", "linkedMetafieldValue": "gid://shopify/Metaobject/971662468" }, { "name": "Yellow", "linkedMetafieldValue": "gid://shopify/Metaobject/971662469" } ] } ] } } }