What's your biggest current challenge? Have your say in Community Polls along the right column.
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: Create multiple metafield one API call

Create multiple metafield one API call

tecoektamerai
Shopify Partner
66 5 17

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 6 (6)

swalkinshaw
Shopify Staff
20 4 12

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.

To learn more visit the Shopify Help Center or the Community Blog.

tecoektamerai
Shopify Partner
66 5 17

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
Visitor
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
8 0 4

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
20 4 12

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.

To learn more visit the Shopify Help Center or the Community Blog.

mohammadliton
Shopify Partner
5 0 0

Hello, It's not possible to update multiple metafields in a single API call. To achieve that you will need to make a separate API call for each metafield.

Best Regards,
Mohammad Liton