skip to Main Content

I want to Create multiple Meta fields with different key but it displaying me following error:

‘metafield’ => ‘expected Array to be a Hash’,

This is my code:

    $prodcut_variant = array(

    'metafield'=>array(
       array('namespace'=>'orbital_response',
             'key'=>'Os Purchases',
             'value'=>'0',
             'value_type'=>integer,),
       array('namespace'=>'orbital_response',
             'key'=>'Stock Status',
             'value'=>'C',
             'value_type'=>integer,)

));

$request_update = $shopify('POST /admin/products/{#ID}/metafields.json',array(),$prodcut_variant);

2

Answers


  1. Remove the comma from key

    'value_type'=>integer,),
    

    like as

    'value_type'=>integer),
    
    Login or Signup to reply.
  2. If you are adding metafields with a new record you can pass an array of metafields. Otherwise you have to create them one at a time at the url ‘/admin/variant/#id/metafields.json

    Your value ‘C’ is not an integer. I suspect the quoted ‘0’ won’t go through either. It is likely these that are throwing the first error. Do you mean 0 or 0xC?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search