productCreate
Requires access scope. Also: The user must have a permission to create products.
Creates a product
with attributes such as title, description, and vendor.
You can use the mutation to define
options and
values
for products with
product variants,
such as different sizes or colors.
To create multiple product variants for a single product and manage prices, use the
mutation.
To create or update a product in a single request, use the
mutation.
Learn more about the product model and adding product data.
Arguments
- Anchor to inputinput•Product
Input! required The properties of the new product.
- Anchor to mediamedia•
The media to add to the product.
Anchor to ProductCreatePayload returnsProductCreatePayload returns
- Anchor to productproduct•
The product object.
- Anchor to shopshop•Shop!non-null
The shop associated with the product.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
- Create a product with an option linked to a metafield
- productCreate reference
Examples
mutation CreateProductWithLinkedOptions($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
productCategory {
productTaxonomyNode {
id
}
}
options {
name
linkedMetafield {
namespace
key
}
optionValues {
name
linkedMetafieldValue
}
}
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CreateProductWithLinkedOptions($input: ProductInput!) { productCreate(input: $input) { userErrors { field message } product { productCategory { productTaxonomyNode { id } } options { name linkedMetafield { namespace key } optionValues { name linkedMetafieldValue } } } } }",
"variables": {
"input": {
"title": "Oversized hoodie",
"productCategory": {
"productTaxonomyNodeId": "gid://shopify/ProductTaxonomyNode/329005233"
},
"productOptions": [
{
"name": "Color",
"linkedMetafield": {
"namespace": "shopify",
"key": "color-pattern",
"values": [
"gid://shopify/Metaobject/971662587",
"gid://shopify/Metaobject/971662588",
"gid://shopify/Metaobject/971662589"
]
}
}
]
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CreateProductWithLinkedOptions($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
productCategory {
productTaxonomyNode {
id
}
}
options {
name
linkedMetafield {
namespace
key
}
optionValues {
name
linkedMetafieldValue
}
}
}
}
}`,
{
variables: {
"input": {
"title": "Oversized hoodie",
"productCategory": {
"productTaxonomyNodeId": "gid://shopify/ProductTaxonomyNode/329005233"
},
"productOptions": [
{
"name": "Color",
"linkedMetafield": {
"namespace": "shopify",
"key": "color-pattern",
"values": [
"gid://shopify/Metaobject/971662587",
"gid://shopify/Metaobject/971662588",
"gid://shopify/Metaobject/971662589"
]
}
}
]
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CreateProductWithLinkedOptions($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
productCategory {
productTaxonomyNode {
id
}
}
options {
name
linkedMetafield {
namespace
key
}
optionValues {
name
linkedMetafieldValue
}
}
}
}
}`,
"variables": {
"input": {
"title": "Oversized hoodie",
"productCategory": {
"productTaxonomyNodeId": "gid://shopify/ProductTaxonomyNode/329005233"
},
"productOptions": [
{
"name": "Color",
"linkedMetafield": {
"namespace": "shopify",
"key": "color-pattern",
"values": [
"gid://shopify/Metaobject/971662587",
"gid://shopify/Metaobject/971662588",
"gid://shopify/Metaobject/971662589"
]
}
}
]
}
},
},
});
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 CreateProductWithLinkedOptions($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
productCategory {
productTaxonomyNode {
id
}
}
options {
name
linkedMetafield {
namespace
key
}
optionValues {
name
linkedMetafieldValue
}
}
}
}
}
QUERY
variables = {
"input": {
"title": "Oversized hoodie",
"productCategory": {
"productTaxonomyNodeId": "gid://shopify/ProductTaxonomyNode/329005233"
},
"productOptions": [{"name"=>"Color", "linkedMetafield"=>{"namespace"=>"shopify", "key"=>"color-pattern", "values"=>["gid://shopify/Metaobject/971662587", "gid://shopify/Metaobject/971662588", "gid://shopify/Metaobject/971662589"]}}]
}
}
response = client.query(query: query, variables: variables)