0
votes

I can post a number of metafields for an existing product if I do it one at a time:

/admin/products/#{id}/metafields.json

{      "metafield":       
    {            
        "namespace":"c_f",
        "key":"label",
        "value":"Am:pm",          
        "value_type":"string"      
    } 

}

When I try to add multiple fields in the same post, I am getting an error:

  {      "metafields":[
        {            
            "namespace":"c_f",
            "key":"artist",
            "value":"CHEMICAL BROTHERS",          
            "value_type":"string"      
        },
        {            
            "namespace":"c_f",
            "key":"label",
            "value":"Virgin",          
            "value_type":"string"      
        }
      ]      
    }

The error is:

"metafield": "Required parameter missing or invalid"

API has examples of posting one metafield only. Is there any way I can combine the metafields (need about 8) into a single POST request?

1
you have the mulitiple example showing as metafields with an S, so the required field metafield is missing.Matthew Darnell
Do you mean replacing metafields with metafield as the top name - this produces another error. Using it as a name inside the array errors as well - unexpected tokenNicolai Kant

1 Answers

8
votes

Try making a PUT request like this one with the product:

PUT /admin/products/5040616004.json HTTP/1.1
Host: yourshop.myshopify.com
X-Shopify-Access-Token: 085abas8bd90325c3f81s8e9c88befc0
Content-Type: application/json

{
  "product": {
    "metafields": [{
      "namespace": "c_f",
      "key": "artist",
      "value": "CHEMICAL BROTHERS",
      "value_type": "string"
    }, {
      "namespace": "c_f",
      "key": "label",
      "value": "Virgin",
      "value_type": "string"
    }]
  }
}