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.

I'm updating a list.product_reference metafield with multiple values but only the first is saved

Solved

I'm updating a list.product_reference metafield with multiple values but only the first is saved

Ashley_Kennerle
Shopify Partner
61 0 8

I have a metafield set up as type list.product_reference and I pass product values like this:

 

Array
                                (
                                    [namespace] => custom
                                    [key] => related_boot_mats
                                    [value] => ["gid:\/\/shopify\/Product\/6904572084410","gid:\/\/shopify\/Product\/6904572248250"]
                                    [type] => list.product_reference
                                )

 

But the response only includes the first product:

 

[node] => Array
                                                                (
                                                                    [key] => related_boot_mats
                                                                    [value] => ["gid://shopify/Product/6904572084410"]
                                                                    [namespace] => custom
                                                                )

 

I can add multiple products using the Shopify admin site, I'm just not able to do it with the API. Is there something that I need to add to allow this? Here's the query:

 

Array
(
    [query] => 
		mutation createOrUpdateProduct($input: ProductInput!) {
			productUpdate(input: $input) {
				product {
					id
					title
					handle
					bodyHtml
					tags
					productType
					vendor
					images(first: 1) {
						edges {
							node {
								src
							}
						}
					}
					variants(first: 1) {
						edges {
							node {
								id
								sku
								price
							}
						}
					}
					metafields(first: 20) {
						edges {
							node {
								key
								value
								namespace
							}
						}
					}
				}
			}
		}
		
    [variables] => Array
        (
            [input] => Array
                (
                  
                    [metafields] => Array
                        (
                            
                            [0] => Array
                                (
                                    [namespace] => custom
                                    [key] => related_boot_mats
                                    [value] => ["gid:\/\/shopify\/Product\/6904572084410","gid:\/\/shopify\/Product\/6904572248250"]
                                    [type] => list.product_reference
                                )

                        )

                    [id] => gid://shopify/Product/6904571756730
                )

        )

)

 

Accepted Solution (1)

Eric-HAN
Shopify Partner
214 27 23

This is an accepted solution.

Hi, there

I dont think it is a suitable way using productUpdate to updates metafield of type “list product reference” directly.    I recommend metafieldsSet mutation instead.

- 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

View solution in original post

Reply 1 (1)

Eric-HAN
Shopify Partner
214 27 23

This is an accepted solution.

Hi, there

I dont think it is a suitable way using productUpdate to updates metafield of type “list product reference” directly.    I recommend metafieldsSet mutation instead.

- 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