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 mediamedia•
The media to add to the product.
- Anchor to productproduct•
The attributes of the new product.
- Anchor to inputinput•Product
Input Deprecated The properties of the new product. Deprecated as of
2024-10
.Use
product
argument instead.
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
- Create a product and associate metafields
- Create a product and return the product ID
- Create a product with a combined listing role
- Create a product with media
- Create a product with product options and option values
- productCreate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation {6 productCreate(product: {title: "Cool socks", productOptions: [{name: "Color", values: [{name: "Red"}, {name: "Blue"}]}, {name: "Size", values: [{name: "Small"}, {name: "Large"}]}]}) {7 product {8 id9 title10 options {11 id12 name13 position14 optionValues {15 id16 name17 hasVariants18 }19 }20 }21 userErrors {22 field23 message24 }25 }26 }`,27);2829const data = await response.json();30
mutation {
productCreate(product: {title: "Cool socks", productOptions: [{name: "Color", values: [{name: "Red"}, {name: "Blue"}]}, {name: "Size", values: [{name: "Small"}, {name: "Large"}]}]}) {
product {
id
title
options {
id
name
position
optionValues {
id
name
hasVariants
}
}
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation { productCreate(product: {title: \"Cool socks\", productOptions: [{name: \"Color\", values: [{name: \"Red\"}, {name: \"Blue\"}]}, {name: \"Size\", values: [{name: \"Small\"}, {name: \"Large\"}]}]}) { product { id title options { id name position optionValues { id name hasVariants } } } userErrors { field message } } }"
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation {
productCreate(product: {title: "Cool socks", productOptions: [{name: "Color", values: [{name: "Red"}, {name: "Blue"}]}, {name: "Size", values: [{name: "Small"}, {name: "Large"}]}]}) {
product {
id
title
options {
id
name
position
optionValues {
id
name
hasVariants
}
}
}
userErrors {
field
message
}
}
}`,
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `mutation {
productCreate(product: {title: "Cool socks", productOptions: [{name: "Color", values: [{name: "Red"}, {name: "Blue"}]}, {name: "Size", values: [{name: "Small"}, {name: "Large"}]}]}) {
product {
id
title
options {
id
name
position
optionValues {
id
name
hasVariants
}
}
}
userErrors {
field
message
}
}
}`,
});
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 {
productCreate(product: {title: "Cool socks", productOptions: [{name: "Color", values: [{name: "Red"}, {name: "Blue"}]}, {name: "Size", values: [{name: "Small"}, {name: "Large"}]}]}) {
product {
id
title
options {
id
name
position
optionValues {
id
name
hasVariants
}
}
}
userErrors {
field
message
}
}
}
QUERY
response = client.query(query: query)
Response
JSON1{2 "productCreate": {3 "product": {4 "id": "gid://shopify/Product/1072481267",5 "title": "Cool socks",6 "options": [7 {8 "id": "gid://shopify/ProductOption/1064576771",9 "name": "Color",10 "position": 1,11 "optionValues": [12 {13 "id": "gid://shopify/ProductOptionValue/1054672637",14 "name": "Red",15 "hasVariants": true16 },17 {18 "id": "gid://shopify/ProductOptionValue/1054672638",19 "name": "Blue",20 "hasVariants": false21 }22 ]23 },24 {25 "id": "gid://shopify/ProductOption/1064576772",26 "name": "Size",27 "position": 2,28 "optionValues": [29 {30 "id": "gid://shopify/ProductOptionValue/1054672639",31 "name": "Small",32 "hasVariants": true33 },34 {35 "id": "gid://shopify/ProductOptionValue/1054672640",36 "name": "Large",37 "hasVariants": false38 }39 ]40 }41 ]42 },43 "userErrors": []44 }45}