What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

Graph QL mutation 'productVariantsBulkCreate' strategy broken

Solved

Graph QL mutation 'productVariantsBulkCreate' strategy broken

HelloToxicity
Shopify Partner
5 1 0

Hey,

I was working with creating a product with variants which had unique prices and inventory quantities and found that the 'REMOVE_STANDALONE_VARIANT' wasn't working. When I try to request productVariantsBulkCreate using that param, I am hit with the error:

      "userErrors": [
        {
          "field": ["variants", "0"],
          "message": "The variant '11 / 2323' already exists. Please change at least one option value."
        }
      ]
 

Don;t mind the weird option names, they were typed in haste. 
The 11/ 2323 variant is created when I add options to the product in my '
productOptionsCreate' which returns this as the variant.

        "variants": {
          "nodes": [
            {
              "id": "gid://shopify/ProductVariant/49370552041756",
              "title": "11 / 2323",
              "selectedOptions": [
                { "name": "test", "value": "11" },
                { "name": "test_2", "value": "2323" }
              ]
            }
          ]
        },

I believe this is an bug, but just in case I will include my full query:

{
  "query": "mutation productVariantsBulkCreate($productId: ID!, $variantsInput: [ProductVariantsBulkInput!]!) {\n  productVariantsBulkCreate(productId: $productId, variants: $variantsInput) {\n    product {\n      id\n    }\n    productVariants {\n      id\n      metafields(first: 1) {\n        edges {\n          node {\n            namespace\n            key\n            value\n          }\n        }\n      }\n    }\n    userErrors {\n      field\n      message\n    }\n  }\n}",
  "variables": {
    "productId": "gid://shopify/Product/9530321109276",
    "strategy": "REMOVE_STANDALONE_VARIANT",
    "variantsInput": [
      {
        "price": 2323,
        "inventoryQuantities": [
          {
            "availableQuantity": 23,
            "locationId": "gid://shopify/Location/98154283292"
          }
        ],
        "optionValues": [
          { "name": "11", "optionName": "test" },
          { "name": "2323", "optionName": "test_2" }
        ]
      },
      {
        "price": 3,
        "inventoryQuantities": [
          {
            "availableQuantity": 43,
            "locationId": "gid://shopify/Location/98154283292"
          }
        ],
        "optionValues": [
          { "name": "11", "optionName": "test" },
          { "name": "232", "optionName": "test_2" }
        ]
      }
    ]
  }
}

Thanks for all the help!

Accepted Solution (1)

HelloToxicity
Shopify Partner
5 1 0

This is an accepted solution.

Found out I was being silly - for anyone stumbling across this in the future the solution is adding the ProductVariantsBulkCreateStrategy  variable to the GQL request.

View solution in original post

Reply 1 (1)

HelloToxicity
Shopify Partner
5 1 0

This is an accepted solution.

Found out I was being silly - for anyone stumbling across this in the future the solution is adding the ProductVariantsBulkCreateStrategy  variable to the GQL request.