Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: Create a Product with Variant and Variant Images using GraphQL API

Solved

Create a Product with Variant and Variant Images using GraphQL API

abishekrs
Shopify Partner
25 3 8

Using the GraphQL API, is there a way to create a product with product variants and images for each variant using a single API call?

Accepted Solution (1)

Geist
Shopify Partner
79 7 8

This is an accepted solution.

https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productCreate

this is how to create a variant

https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productVariantCreate

 

here is your answer. You need to use the productCreate mutation AND the productVariantCreate mutation. You can‘t set it from one call. You could just wrap them both in a single function though

- Shopify Headless Ecommerce Experts
- Site speed optimization
- Composable Commerce
Geist - Headless Shopify Ecommerce Expert

View solution in original post

Replies 7 (7)

Geist
Shopify Partner
79 7 8

This is an accepted solution.

https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productCreate

this is how to create a variant

https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productVariantCreate

 

here is your answer. You need to use the productCreate mutation AND the productVariantCreate mutation. You can‘t set it from one call. You could just wrap them both in a single function though

- Shopify Headless Ecommerce Experts
- Site speed optimization
- Composable Commerce
Geist - Headless Shopify Ecommerce Expert
abishekrs
Shopify Partner
25 3 8

@Geist my question was more about creating the product using the GraphQL. Since product creation using REST is being deprecated, I am moving all my code to use the GraphQL and was wondering how I go about doing this in a single call.

Geist
Shopify Partner
79 7 8

in graphql every fetch call is a POST request so if you want to update the server you must use a mutation. I would note that each call to the graphql admin api must come from a server. You cant hit it from the front end. You either need to get a backend app up and running or use a serverless function

- Shopify Headless Ecommerce Experts
- Site speed optimization
- Composable Commerce
Geist - Headless Shopify Ecommerce Expert
abishekrs
Shopify Partner
25 3 8

I understand, how to make the GraphQL calls using a server. Just figuring out if there is a way to create a product

- with 2 Options and 6 Option values
- with 20 images

- with 100+ variants 

 

All of the above using a single graphQL call using the mutation query.

Geist
Shopify Partner
79 7 8

No you can‘t do it with a single call. Creating a product requires one mutation creating a variant requires another mutation.

- Shopify Headless Ecommerce Experts
- Site speed optimization
- Composable Commerce
Geist - Headless Shopify Ecommerce Expert

AsafGitai
Shopify Staff
109 16 45

Hi @abishekrs 

We are working on adding file creation to productSet, stay tuned 

abishekrs
Shopify Partner
25 3 8

I was looking at the same, just trying to find examples on how to do that.