How to add multiple metafields in customer

New Member
3 0 0

I am trying to add multiple metafields in a single post. 

$data = array( 
	'customer' => array(
		'id' => $customer_id,
		'metafield' =>
		  array(
                'key' => 'od_sph',
                'value' => $params['od_sph'],
                'value_type' => 'string',               
                'namespace' => 'global'
            ),
            array(
                'key' => 'os_sph',
                'value' => $params['os_sph'],
                'value_type' => 'string',               
                'namespace' => 'global'
            ),
            array(
                'key' => 'os_cyl',
                'value' => $params['os_cyl'],
                'value_type' => 'string',               
                'namespace' => 'global'
            ),
            array(
                'key' => 'os_add',
                'value' => $params['os_add'],
                'value_type' => 'string',               
                'namespace' => 'global'
            )         
		)
   );

It adds only a single metafield. Please help. 

0 Likes
Highlighted
Shopify Partner
1053 113 167

Correct, because "metafield" as the name suggests is not a list, it holds a single object (i.e. PHP array). The rest are ignored as they are not event assigned to the "metafield" field, not sure how this is serialized into JSON.

 

What is the endpoint you are sending your requests to, which method?

 

 

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes