【问题标题】:Shopify. Problems updating Metafields with shopify-node-api购物。使用 shopify-node-api 更新元字段时出现问题
【发布时间】:2014-05-12 07:56:53
【问题描述】:

我在使用 Shopify API 更新现有元字段时遇到了困难。每次我收到一个错误,建议我该变体已经存在......所以它一定认为我正在尝试创建一个新的(而不是更新)。

我认为这可能是 'put' 和 'post' 的问题 - 所以将我的方法更改为 put,但错误仍然存​​在。我已经硬连线了所有变量,以便于测试。

我正在与 Cloudinary 合作。我在 Express.js 中使用 https://github.com/sinechris/shopify-node-api

app.post('/upload', function(req, res){
  // upload page... assume we have uploaded our image - but have hard-wired a local file in for now
  cloudinary.uploader.upload('/Users/Rob/Pictures/testimg.jpg', function(savedImg) { 
    var imageURL = savedImg.url;
    console.log(imageURL)
  },
  {
    public_id: "testimg"
  });


  // the saved image is returned - so we add it to our updateMetafieldData json object
      var updateMetafieldData = {
       "variant": {
          "id": '253818949',
          "metafields": [
            {
              "key": "variant_image_0",
              "value": 'testimg', // whatever the public id of our image is.
              "value_type": "string",
              "namespace": "variant_image"
            }
          ]
        }
      }
  // and post the result to shopify - then redirect to /getvariants
  Shopify.put('/admin/variants/253818949.json', updateMetafieldData, function(data){
    // res.redirect('/getvariants')
  });



});

【问题讨论】:

  • 我已经通过删除元字段来解决这个问题......但理想情况下希望进行更新。

标签: node.js express shopify


【解决方案1】:

我实际上创建了 Shopify Node API,并且在这几个月后才刚刚发生,但我想我会回答其他人的问题。

在此处查看 shopify API:https://docs.shopify.com/api/metafield#update

您可以通过对元字段资源执行 PUT 请求来直接更新元字段,而不是像这样的变体:

/admin/metafields/#{id}.json

您当然需要先知道元字段的 ID,这样就需要先调用变体,或者您可以简单地将 ID 存储在本地数据库中以供参考。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-25
相关资源
最近更新 更多