productOptionUpdate
Requires access scope. Also: The user must have a permission to edit products and manage product variants.
Updates a product option.
Arguments
- Anchor to optionoption•Option
Update requiredInput! Option to update.
- Anchor to optionValuesToAddoption•
Values To Add New option values to create.
- Anchor to optionValuesToDeleteoption•
Values To Delete IDs of the existing option values to delete.
- Anchor to optionValuesToUpdateoption•
Values To Update Existing option values to update.
- Anchor to productIdproduct•
Id ID!required The ID of the Product the Option belongs to.
- Anchor to variantStrategyvariant•
Strategy The strategy defines which behavior the mutation should observe regarding variants, such as creating variants or deleting them in response to option values to add or to delete. If not provided or set to null, the strategy
will be used.
Anchor to ProductOptionUpdatePayload returnsProductOptionUpdatePayload returns
- Anchor to productproduct•
The product with which the option being updated is associated.
- Anchor to userErrorsuser•
Errors [ProductOption non-nullUpdate User Error!]! The list of errors that occurred from executing the mutation.
- Add 2 new option values and update an existing one
- Replace a value with another
- Trying to add an option value with a name that already exists returns an error
- Update name and position of an option
- Update the values of an option linked to a metafield
- productOptionUpdate reference
Examples
mutation updateOption($productId: ID!, $option: OptionUpdateInput!, $optionValuesToAdd: [OptionValueCreateInput!], $optionValuesToUpdate: [OptionValueUpdateInput!], $optionValuesToDelete: [ID!], $variantStrategy: ProductOptionUpdateVariantStrategy) {
productOptionUpdate(productId: $productId, option: $option, optionValuesToAdd: $optionValuesToAdd, optionValuesToUpdate: $optionValuesToUpdate, optionValuesToDelete: $optionValuesToDelete, variantStrategy: $variantStrategy) {
userErrors {
field
message
code
}
product {
id
options {
id
name
values
position
optionValues {
id
name
hasVariants
}
}
variants(first: 5) {
nodes {
id
title
selectedOptions {
name
value
}
}
}
}
}
}
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 updateOption($productId: ID!, $option: OptionUpdateInput!, $optionValuesToAdd: [OptionValueCreateInput!], $optionValuesToUpdate: [OptionValueUpdateInput!], $optionValuesToDelete: [ID!], $variantStrategy: ProductOptionUpdateVariantStrategy) { productOptionUpdate(productId: $productId, option: $option, optionValuesToAdd: $optionValuesToAdd, optionValuesToUpdate: $optionValuesToUpdate, optionValuesToDelete: $optionValuesToDelete, variantStrategy: $variantStrategy) { userErrors { field message code } product { id options { id name values position optionValues { id name hasVariants } } variants(first: 5) { nodes { id title selectedOptions { name value } } } } } }",
"variables": {
"productId": "gid://shopify/Product/1072481063",
"option": {
"id": "gid://shopify/ProductOption/1064576526"
},
"optionValuesToAdd": [
{
"name": "Yellow"
},
{
"name": "Red"
}
],
"optionValuesToUpdate": [
{
"id": "gid://shopify/ProductOptionValue/1054672275",
"name": "Purple"
}
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation updateOption($productId: ID!, $option: OptionUpdateInput!, $optionValuesToAdd: [OptionValueCreateInput!], $optionValuesToUpdate: [OptionValueUpdateInput!], $optionValuesToDelete: [ID!], $variantStrategy: ProductOptionUpdateVariantStrategy) {
productOptionUpdate(productId: $productId, option: $option, optionValuesToAdd: $optionValuesToAdd, optionValuesToUpdate: $optionValuesToUpdate, optionValuesToDelete: $optionValuesToDelete, variantStrategy: $variantStrategy) {
userErrors {
field
message
code
}
product {
id
options {
id
name
values
position
optionValues {
id
name
hasVariants
}
}
variants(first: 5) {
nodes {
id
title
selectedOptions {
name
value
}
}
}
}
}
}`,
{
variables: {
"productId": "gid://shopify/Product/1072481063",
"option": {
"id": "gid://shopify/ProductOption/1064576526"
},
"optionValuesToAdd": [
{
"name": "Yellow"
},
{
"name": "Red"
}
],
"optionValuesToUpdate": [
{
"id": "gid://shopify/ProductOptionValue/1054672275",
"name": "Purple"
}
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation updateOption($productId: ID!, $option: OptionUpdateInput!, $optionValuesToAdd: [OptionValueCreateInput!], $optionValuesToUpdate: [OptionValueUpdateInput!], $optionValuesToDelete: [ID!], $variantStrategy: ProductOptionUpdateVariantStrategy) {
productOptionUpdate(productId: $productId, option: $option, optionValuesToAdd: $optionValuesToAdd, optionValuesToUpdate: $optionValuesToUpdate, optionValuesToDelete: $optionValuesToDelete, variantStrategy: $variantStrategy) {
userErrors {
field
message
code
}
product {
id
options {
id
name
values
position
optionValues {
id
name
hasVariants
}
}
variants(first: 5) {
nodes {
id
title
selectedOptions {
name
value
}
}
}
}
}
}`,
"variables": {
"productId": "gid://shopify/Product/1072481063",
"option": {
"id": "gid://shopify/ProductOption/1064576526"
},
"optionValuesToAdd": [
{
"name": "Yellow"
},
{
"name": "Red"
}
],
"optionValuesToUpdate": [
{
"id": "gid://shopify/ProductOptionValue/1054672275",
"name": "Purple"
}
]
},
},
});
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 updateOption($productId: ID!, $option: OptionUpdateInput!, $optionValuesToAdd: [OptionValueCreateInput!], $optionValuesToUpdate: [OptionValueUpdateInput!], $optionValuesToDelete: [ID!], $variantStrategy: ProductOptionUpdateVariantStrategy) {
productOptionUpdate(productId: $productId, option: $option, optionValuesToAdd: $optionValuesToAdd, optionValuesToUpdate: $optionValuesToUpdate, optionValuesToDelete: $optionValuesToDelete, variantStrategy: $variantStrategy) {
userErrors {
field
message
code
}
product {
id
options {
id
name
values
position
optionValues {
id
name
hasVariants
}
}
variants(first: 5) {
nodes {
id
title
selectedOptions {
name
value
}
}
}
}
}
}
QUERY
variables = {
"productId": "gid://shopify/Product/1072481063",
"option": {
"id": "gid://shopify/ProductOption/1064576526"
},
"optionValuesToAdd": [{"name"=>"Yellow"}, {"name"=>"Red"}],
"optionValuesToUpdate": [{"id"=>"gid://shopify/ProductOptionValue/1054672275", "name"=>"Purple"}]
}
response = client.query(query: query, variables: variables)