Shopify Admin API - Create Product

Hello,

I am trying out the shopify admin API, and I have reason to believe that it doesn’t work as intended when creating a product. Can you please confirm

I send this mutation:

mutation {
  productCreate(input:{
      title: "aa - Magnus Test Product", 
  productType: "Print", 
  vendor: "Test",
  status: DRAFT,
    productOptions: [{
      name: "Størrelse",
      position: 1,
      values: [
        {name: "A4 (21x29.7 cm)"},
        {name:"30x40 cm"}, 
        {name: "50x70 cm"}
      ]
    },
    {
        name: "Ramme",
        position:2,
        values: [
            {name: "Ingen ramme"},
            {name: "Sort ramme"},
            {name: "Massiv eg"},
            {name: "Hvid ramme"},
            {name: "Ege look"}
        ]
    }
    ]
  }) {
    product {
      id,
        options (first: 100) {
        name,
        optionValues {
          name,  
        }
      }
    }
  }
}

And get this response:

{
    "data": {
        "productCreate": {
            "product": {
                "id": "gid://shopify/Product/9446736462165",
                "options": [
                    {
                        "name": "Størrelse",
                        "optionValues": [
                            {
                                "name": "A4 (21x29.7 cm)"
                            },
                            {
                                "name": "30x40 cm"
                            },
                            {
                                "name": "50x70 cm"
                            }
                        ]
                    },
                    {
                        "name": "Ramme",
                        "optionValues": [
                            {
                                "name": "Ingen ramme"
                            },
                            {
                                "name": "Sort ramme"
                            },
                            {
                                "name": "Massiv eg"
                            },
                            {
                                "name": "Hvid ramme"
                            },
                            {
                                "name": "Ege look"
                            }
                        ]
                    }
                ]
            }
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 12,
            "actualQueryCost": 12,
            "throttleStatus": {
                "maximumAvailable": 2000,
                "currentlyAvailable": 1988,
                "restoreRate": 100
            }
        }
    }
}

So far, so good.

It seems like shopify does correctly catch my options. The thing is visible whenever I query the product by ID. HOWEVER

When i go to the UI of the product, it doesn’t quite seem to work.

I can only see the first of the two options, and then a variant has been created for the combination of the two options.

“A4 / ingen ramme” for example (see image as well)

How come this is only created for the first combinations, and what is the approach to make it happen for all?

Best regards,

magnussampson

Hi @magnussampson ,

Since each variant can have a maximum of 3 options, please try again.

mutation {
  productCreate(input:{
      title: "aa - Magnus Test Product", 
  productType: "Print", 
  vendor: "Test",
  status: DRAFT,
    productOptions: [
    {
      name: "Størrelse",
      position: 1,
      values: [
        {name: "A4 (21x29.7 cm)"},
        {name:"30x40 cm"}, 
        {name: "50x70 cm"}
      ]
    },
    {
        name: "Ramme",
        position:2,
        values: [
            {name: "Ingen ramme"},
            {name: "Sort ramme"},
            {name: "Massiv eg"}
        ]
    }
    ]
  }) {
    product {
      id,
        options (first: 100) {
        name,
        optionValues {
          name,  
        }
      }
    }
  }
}

Hi! Thanks for the quick answer. Unfortunately that didn’t change anything.

AS before I seem to get the correct response but when looking in the UI I’ve only managed to create one of the provided options

Best regards,

Magnus

Hi,there

I think this is the default behavior. Shopify’s default behavior ensures that products have at least one variant. By using the Product query GraphQL , you can easily check the presence of variants for a product, you will find there is a filed called hasVariant of every option. Only you create the productVariant explicitly for corresponding option combination . The variant in UI can be visible.