Create multiple metafield one API call

tecoektamerai
Tourist
7 0 0

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.

0 Likes
swalkinshaw
Shopify Staff
Shopify Staff
9 2 2

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.

0 Likes
tecoektamerai
Tourist
7 0 0

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>";
0 Likes