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.

Re: Create products without variant/options using productSet

Create products without variant/options using productSet

matthewmayer
Visitor
2 0 2

I'm trying to follow the guide to sync data from an external source using the productSet migration https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/sync-data

 

My mutation looks like this:

 

 

 

 

mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {
    productSet(synchronous: $synchronous, input: $productSet) {
        product {
            id
        }
        productSetOperation {
            id
            status
            userErrors {
                code
                field
                message
            }
        }
        userErrors {
            code
            field
            message
        }
    }
}

 

 

 

 

 

I want to sync title, description and price so my productSet looks like this.

 

 

 

 

 

const productSet = {
            title: product.name,
            descriptionHtml: product.description,
            vendor: product.vendor,
            productOptions: [{
                name: "Dummy",
                position: 1,
                values: [{
                    name: "High"
                }]
            }],
            variants: [{
                optionValues: [{
                    optionName: "Dummy",
                    name: "High"
                }],
                price: product.price
            }]
        }

 

 

 

 

 

I don't want the dummy "productOptions" to be needed as it shows up on the product listing. But if i omit productOptions/optionValues i get an error like:

 

Variable $productSet of type ProductSetInput! was provided invalid value for variants.0.optionValues (Expected value to not be null)

 

How can i create a simple product with one price and no options/variants?

 

Replies 5 (5)

Liam
Community Manager
3108 342 884

Hi Matthew,

 

Using the same mutation you could structure your variables to be something like this:

 

{
    "productSet": {
        "title": "Sample Product",
        "descriptionHtml": "<p>This is a sample product description.</p>",
        "vendor": "Sample Vendor",
        "productOptions": [
            {
                "name": "Title",
                "values": [
                    {"name": "Default Title"}
                ]
            }
        ],
        "variants": [
            {
                "price": "19.99",
                "optionValues": [
                    {
                        "optionName": "Title",
                        "name": "Default Title"
                    }
                ]
            }
        ]
    },
    "synchronous": false
}

Would this work for you?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

matthewmayer
Visitor
2 0 2

yes that does work. i dont totally understand why my version gave me a selector for selecting the "Dummy" field on the product page, but your "Title" product option is invisible?

B__
Shopify Partner
11 1 5

Hi Liam,

 

Although this works, all products are created with one variant instead of the (normally hidden) default variant. This means that some themes won't show a quick buy button. Also, some themes show the option names and values on the product detail page, which normally is just 'Default title'.

 

Is there any way that productSet can be used to import simple products (only default variant) without having an option value and option name?

AV_SL
Shopify Partner
39 4 10

@Liam Thanks for this response - but this doesn't create a default variant - see here for the test:
https://community.shopify.com/c/graphql-basics-and/how-do-you-create-a-product-with-the-default-vari...

Do you have any insight as to how to create a default variant with productSet?

EDIT: never mind, the issue was capitalisation:
The correct value is related to capitalisation - it needs to be "Default Title" not "Default title" - to generate a default variant

Biscuits Bundles App - Create beautiful mix and match bundles using native Shopify bundles functionality.
B__
Shopify Partner
11 1 5
Hi AV_SL,

If you create the default variant exactly as Liam described (case
sensitive!!) , it works for me