Shopify - 添加多个元区域

时间:2016-07-25 21:24:08

标签: shopify

如果我一次只使用一个现有产品,我可以发布一些元字段:

/管理/产品/#{ID} /metafields.json

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

}

当我尝试在同一帖子中添加多个字段时,我收到错误:

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

错误是:

"metafield": "Required parameter missing or invalid"

API包含仅发布一个元数据的示例。有什么方法可以将元数据(需要大约8个)组合成一个POST请求吗?

1 个答案:

答案 0 :(得分:6)

尝试使用该产品发出PUT请求like this one

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"
    }]
  }
}