Create multiple metafield one API call

tecoektamerai
Shopify Partner
66 5 14

Hello

Hope you all are well!!!

I have been stuck in 1 point. I want to create multiple metafields at one API call. but not working... can somebody please help me.

Replies 5 (5)
swalkinshaw
Shopify Staff
Shopify Staff
20 4 9

Hello, this is possible in our GraphQL API. For example, with the `productUpdate` mutation you can input multiple metafields. See https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/productupdate?#product...for the product example.

tecoektamerai
Shopify Partner
66 5 14

Hello @swalkinshaw 

Hope you are well!! I'm using REST admin api for product metafield. I want to post this both metafields vlalue using REST admin api .

My code:

$array1 = array (
	  'product' => 
	  array (
		'metafields' => 
		array (
		  0 => 
		  array (
			'namespace' => 'your_namespace',
			'key' => 'your_key',
			'value' => 'your_value',
			'value_type' => 'string',
		  ),
		  1 => 
		  array (
			'namespace' => 'your_namespace_2',
			'key' => 'your_key_2',
			'value' => 'your_value',
			'value_type' => 'string',
		  ),
		),
	  ),
	);

	 $getmetafields = shopify_call($token, $shop, "/admin/api/2021-04/products/6406423871657/metafields.json", $array1, 'POST'); 
	$getmetafields = json_decode($getmetafields['response'], JSON_PRETTY_PRINT); 
	 echo "<pre>";
	print_r($getmetafields);
	echo "</pre>";
Alex_Dehban
New Member
1 0 0

Hi,

This is my question too.
Is there any way to add necessary meta fields to one level above the products?

I mean adding meta fields somehow that could be assigned automatically to every new product, It's not reasonable to send a separate request for every single field, imaging all of my 1000 products have 50 fields, so how it will be handled?

Really I need to make 50000 requests?

Or I'm totally wrong here?

davidalarcon
Shopify Partner
7 0 1

Did you have any answer related to this?

 

I am also interested in creating different metafields in one single call if possible.

swalkinshaw
Shopify Staff
Shopify Staff
20 4 9

We released a new and improved metafieldsSet mutation in our GraphQL Admin API: https://shopify.dev/api/admin-graphql/2021-10/mutations/metafieldsSet as part of the 2021-10 API version.

 

It lets you create or update multiple (up to 25) metafields on _different_ owners as well.