GraphQL ProductUpdate mutation with metafields fails

Solved
Highlighted
Tourist
21 0 1
The productUpdate mutation is failing when the update request has metafields at the ProductVariant level. It works fine without the metafields.
 I get the following error. Internal error. Looks like something went wrong on our end. Request ID: ec9a0db6-fad8-4c56-a251-3873429b2c82 (include this in support requests).
 

API Request: 

 

mutation ProductUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
      createdAt
      updatedAt
      handle
      title
      metafields(first: 10) {
        edges {
          node {
            id
            key
            namespace
            value
            valueType
          }
        }
      }
      totalInventory
      variants(first: 1) {
        edges {
          node {
            id
            createdAt
            updatedAt
            barcode
            sku
            inventoryQuantity
            inventoryItem {
              id
              createdAt
              updatedAt
              sku
              tracked
              locationsCount
            }
            metafields(first: 10) {
              edges {
                node {
                  id
                  key
                  namespace
                  value
                  valueType
                }
              }
            }
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}
{"input": {
  "id":"gid://shopify/Product/4269148242001",
  "title":"Bataleon Omni MALE 154 Snowboard",
  "vendor":"Bataleon",
  "productType":"snowboards",
  "metafields":[
    {
      "id":"gid://shopify/Metafield/11032304287825",
      "key":"groupingKey",
      "namespace":"products",
      "value":"8719638710183",
      "valueType":"STRING"
    }
  ],
  "variants":[
    {
      "barcode":"8719638710183",
      "sku":"BATALEON-10.20.OMN.154",
      "inventoryItem":{
        "cost":"317.97",
        "tracked":true
      },
      "inventoryQuantities":[
        {
          "locationId":"gid://shopify/Location/24044666961",
          "availableQuantity":10
        }
      ],
      "price":"529.95",
      "compareAtPrice":"529.95",
      "metafields":[
        {
          "id":"gid://shopify/Metafield/11032304222289",
          "key":"attr:genderPreference",
          "namespace":"products",
          "value":"MALE",
          "valueType":"STRING"
        },

        {
          "id":"gid://shopify/Metafield/11032304255057",
          "key":"map",
          "namespace":"products",
          "value":"529.95",
          "valueType":"STRING"
        }
      ]
    }
  ]
}
}

API Response:

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: ec9a0db6-fad8-4c56-a251-3873429b2c82 (include this in support requests)."
    }
  ]
}

 

 

 

 

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 127

Hey @cur8d ,

 

Thank you for providing the X-Request-ID! From the logs, it appears that in the input of your productUpdate mutation you passed in the Variants Metafield ID of `gid://shopify/Metafield/11032304222289`. However from my investigation, it appears that this specific Metafield ID does not currently exist on the Product Variant (id: `gid://shopify/ProductVariant/31638881566801`) you were trying to update. This specific Product Variant has 3 Metafields already attached to it, but none of them match the Metafield ID you specified in the input. I believe it is due to this that the error was thrown.  

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Tourist
21 0 1

@hassain My bad on the GraphQL input data I fixed the ids but I am still getting errors in the update response.

 

Here are the steps to reproduce:

GraphQL mutation:

mutation ProductUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
      createdAt
      updatedAt
      handle
      title
      metafields(first: 10) {
        edges {
          node {
            id
            key
            namespace
            value
            valueType
          }
        }
      }
      totalInventory
      variants(first: 1) {
        edges {
          node {
            id
            createdAt
            updatedAt
            barcode
            sku
            inventoryQuantity
            inventoryItem {
              id
              createdAt
              updatedAt
              sku
              tracked
              locationsCount
            }
            metafields(first: 10) {
              edges {
                node {
                  id
                  key
                  namespace
                  value
                  valueType
                }
              }
            }
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

Request data for metadata creation:

 

{"input": {
  "id":"gid://shopify/Product/4269149913169",
  "title":"Bataleon Omni MALE 154 Snowboard",
  "vendor":"Bataleon",
  "productType":"snowboards",
  "metafields":[
    {
      "id": "gid://shopify/Metafield/11032310251601",
      "description": null,
      "key": "groupingKey",
      "value": "8719638711142",
      "valueType": "STRING"
    }
  ],
  "variants":[
    {
      "barcode":"8719638711142",
      "sku":"BATALEON-10.20.DIS.151",
      "inventoryItem":{
        "cost":"317.97",
        "tracked":true
      },
      "inventoryQuantities":[
        {
          "locationId":"gid://shopify/Location/24044666961",
          "availableQuantity":10
        }
      ],
      "price":"399.95",
      "compareAtPrice":"429.95",
      "metafields":[
      	{
           "key": "attr:genericSize",
            "value": "151",
            "valueType": "STRING",
            "namespace": "variants"
        }
      ]
    }
  ]
}
}

Response:

"data": {
    "productUpdate": {
      "product": {
        "id": "gid://shopify/Product/4269149913169",
        "createdAt": "2019-10-16T18:39:02Z",
        "updatedAt": "2019-12-24T00:47:07Z",
        "handle": "bataleon-disaster-151-male-snowboard",
        "title": "Bataleon Omni MALE 154 Snowboard",
        "metafields": {
          "edges": [
            {
              "node": {
                "id": "gid://shopify/Metafield/11032310251601",
                "key": "groupingKey",
                "namespace": "products",
                "value": "8719638711142",
                "valueType": "STRING"
              }
            }
          ]
        },
        "totalInventory": 10,
        "variants": {
          "edges": [
            {
              "node": {
                "id": "gid://shopify/ProductVariant/31673141231697",
                "createdAt": "2019-12-24T00:47:07Z",
                "updatedAt": "2019-12-24T00:47:07Z",
                "barcode": "8719638711142",
                "sku": "BATALEON-10.20.DIS.151",
                "inventoryQuantity": 10,
                "inventoryItem": {
                  "id": "gid://shopify/InventoryItem/33211642183761",
                  "createdAt": "2019-12-24T00:47:07Z",
                  "updatedAt": "2019-12-24T00:47:07Z",
                  "sku": "BATALEON-10.20.DIS.151",
                  "tracked": true,
                  "locationsCount": 1
                },
                "metafields": {
                  "edges": [
                    {
                      "node": {
                        "id": "gid://shopify/Metafield/11670003122257",
                        "key": "attr:genericSize",
                        "namespace": "variants",
                        "value": "151",
                        "valueType": "STRING"
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      },
      "userErrors": []
    }
  }

Product Update with Metadaupdate: The only different from the creation/update is the metadata id copied as is from the response above.

{"input": {
  "id":"gid://shopify/Product/4269149913169",
  "title":"Bataleon Omni MALE 154 Snowboard",
  "vendor":"Bataleon",
  "productType":"snowboards",
  "metafields":[
    {
      "id": "gid://shopify/Metafield/11032310251601",
      "description": null,
      "key": "groupingKey",
      "value": "8719638711142",
      "valueType": "STRING"
    }
  ],
  "variants":[
    {
      "barcode":"8719638711142",
      "sku":"BATALEON-10.20.DIS.151",
      "inventoryItem":{
        "cost":"317.97",
        "tracked":true
      },
      "inventoryQuantities":[
        {
          "locationId":"gid://shopify/Location/24044666961",
          "availableQuantity":10
        }
      ],
      "price":"399.95",
      "compareAtPrice":"429.95",
      "metafields":[
      	{
          "id": "gid://shopify/Metafield/11670003122257",
           "key": "attr:genericSize",
            "value": "152",
            "valueType": "STRING",
            "namespace": "variants"
        }
      ]
    }
  ]
}
}

GraphQL response:

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: 350743b8-bac4-4378-acb9-d208a84b1cb2 (include this in support requests)."
    }
  ]
}
0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 127

This is an accepted solution.

Hi @cur8d ,

 

Thanks for providing the update and for providing the reproduction steps.

 

From looking at the logs of your latest X-Request-ID, I can see the error message that appears in our platform logs is "RecordNotFound: Couldn't find Metafield with ID=11670003122257 for ProductVariant with ID=>". This message and subsequent testing on my end led me to realize that the reason why you were getting this error is because in your ProductInput variable you are not specifying the `id` attribute of the Product Variant that needs it's Metafield updated. Because you are not specifying the Product Variant's ID, Shopify cannot find the specific Metafield to be updated so eventually the error is thrown.

 

To resolve this issue, update your ProductInput variable to the following:

 

{"input": {
  "id":"gid://shopify/Product/4269149913169",
  "title":"Bataleon Omni MALE 154 Snowboard",
  "vendor":"Bataleon",
  "productType":"snowboards",
  "metafields":[
    {
      "id": "gid://shopify/Metafield/11032310251601",
      "description": null,
      "key": "groupingKey",
      "value": "8719638711142",
      "valueType": "STRING"
    }
  ],
  "variants":[
    {
      "id": "gid://shopify/ProductVariant/31673154732113",
      "barcode":"8719638711142",
      "sku":"BATALEON-10.20.DIS.151",
      "inventoryItem":{
        "cost":"317.97",
        "tracked":true
      },
      "inventoryQuantities":[
        {
          "locationId":"gid://shopify/Location/24044666961",
          "availableQuantity":10
        }
      ],
      "price":"399.95",
      "compareAtPrice":"429.95",
      "metafields":[
      	{
          "id": "gid://shopify/Metafield/11670003122257",
           "key": "attr:genericSize",
            "value": "152",
            "valueType": "STRING",
            "namespace": "variants"
        }
      ]
    }
  ]
}
}

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Tourist
21 0 1

Aha thats works! Thanks for the solution. 

As a suggestion, may be this should be returned as an error message in the response itself, would definitely save time in debugging.

0 Likes