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.

Re: Updating product and product metafields with single PUT request

Updating product and product metafields with single PUT request

Drew_Westphal
Tourist
3 0 4

Hi all, 

In order to conserve calls to the API, I have been trying for the last couple of days to issue a PUT request against a specific product endpoint (i.e. https://help.shopify.com/api/reference/product#update) and update not only the product variants, but also update associated product metafields. The update works except when I include existing metafields.

Even when I include the existing metafield ID in the metafield portion of the array, I get a 4xx response telling me that there is a key collision in the metafield namespace. This suggests to the me that the API thinks I am trying to create the metafield, rather than update it.

I have all but given up (and have started pursuing a more call-intensive field-by-field caching and update strategy), but a support rep told me today that he thought this was possible. 

Can anyone shed any light on using PUT to update a product AND its extant metafields? Is this possible? Can you share a properly formatted JSON request body that succeeds in doing this? 

I appreciate any help, even if it's a definitive no. Doing the suboptimal is much less galling when it is inevitable.

Replies 2 (2)

Drew_Westphal
Tourist
3 0 4

I would have given up were it not for this thread, which seems to indicate updating product metafields with PUT is possible: https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/product-variant-metafields-are-not-bei... (see image for pullquote). 

Below is a copy of the failing JSON (which succeeds if the metafields are removed). Again this works on POST, but not PUT. 

 

{
    "title": "Second Track",
    "body_html": "Second Track by Jonathan Coulton. From the album Test Album. Released in 2009.",
    "product_type": "Parallel Testing",
    "vendor": "Jonathan Coulton",
    "tags": "Test_Album",
    "variants": [
        {
            "title": "MP3",
            "price": 1,
            "sku": "11610:MP3",
            "option1": "MP3",
            "taxable": true,
            "id": 33351292870
        },
        {
            "title": "MP4",
            "price": 1,
            "sku": "11610:MP4",
            "option1": "MP4",
            "taxable": true,
            "id": 33351292934
        },
        {
            "title": "FLAC",
            "price": 1,
            "sku": "11610:FLAC",
            "option1": "FLAC",
            "taxable": true,
            "id": 33351292998
        },
        {
            "title": "ALAC",
            "price": 1,
            "sku": "11610:ALAC",
            "option1": "ALAC",
            "taxable": true,
            "id": 33351293062
        }
    ],
    "options": [
        {
            "name": "Format"
        }
    ],
    "images": [
        {
            "src": "http:\/\/www.jonathancoulton.com\/images\/jc-face-blog-thumb.jpg",
            "id": 21235301510
        }
    ],
    "metafields": [
        {
            "namespace": "global",
            "key": "wiki_link",
            "value": "http:\/\/apple.com",
            "value_type": "string",
            "id": 30591209990
        }
    ],
    "image": {
        "src": "http:\/\/www.jonathancoulton.com\/images\/jc-face-blog-thumb.jpg",
        "id": 21235301510
    },
    "id": 9143746566
}

 

Drew_Westphal
Tourist
3 0 4

Well, this is a little embarassing. Turns out that you CAN do this... AND that the JSON I posted was correct, but that what I was passing to my post function was different and I didn't notice.

Wish there were a "delete thread" button (and there probably is and it's right under my nose and I just don't see it).