Shopify Admin API - Create Product

Shopify Admin API - Create Product

magnussampson
Visitor
2 0 0

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)

magnussampson_0-1720304368768.png

 

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

 

Best regards,

magnussampson

Replies 3 (3)

BSSCommerce-TC
Shopify Partner
215 46 48

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,  
        }
      }
    }
  }
}

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.


MIDA: Heatmap, Record & Replay |BLOOP Referral Program, Reward |

Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
magnussampson
Visitor
2 0 0

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

Eric-HAN
Shopify Partner
99 15 8

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. 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee