Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Existing variant id assigned to new variant

Existing variant id assigned to new variant

mcepo
Shopify Partner
5 0 6

I have run into a bit of strange behavior that happens while updating products through Shopify admin Graphql api.

 

The situation is:

1. A product is created in Shopify with two variants first with color A and second with color B

2. After the product was created, a third variant is added with the same color B that already exists on the second variant

3. When updating that product (with duplicate options), I got a valid response, only 2 variants in the response, not 3, and the SKU on the second variant was updated with the data from the third variant. The third variant wasn't created.

 

This is the sample request I sent using the bulk API:

 

{
  "input": {
    "options": [
      "Colour"
    ],
    "variants": [
      {
        "price": 10.35,
        "compareAtPrice": 12.95,
        "sku": "1000023",
        "id": "48988948955415",
        "options": [
          "A"
        ]
      },
      {
        "price": 10.35,
        "compareAtPrice": 12.95,
        "sku": "1000024",
        "id": "48988948988183",
        "options": [
          "B"
        ]
      },
      {
        "price": 10.35,
        "compareAtPrice": 12.95,
        "sku": "1000025",
        "inventoryManagement": "SHOPIFY",
        "inventoryPolicy": "DENY",
        "options": [
          "B"
        ]
      }
    ],
    "id": "9433084887319"
  }
}

 

 

This is the response I got. Note only two variants in the response and no error and the sku changed on the existing variant:

 

{
  "data": {
    "id": "9433084887319",
    "variants": [
      {
        "id": "48988948955415",
        "sku": "1000023",
        "inventoryItem": {
          "id": "51034378043671"
        }
      },
      {
        "id": "48988948988183",
        "sku": "1000025",
        "inventoryItem": {
          "id": "51034378076439"
        }
      }
    ]
  },
  "__lineNumber": 0,
  "error": null
}

Is this expected behavior? Should we make sure the options are unique before sending them? It is a bit strange to me that sometimes duplicated options are returned as an error but then sometimes variants are just merged.

Replies 0 (0)