相关疑难解决方法(0)

Contentful API 在条目更新时返回“版本不匹配”

我尝试使用 Contentful 的内容管理 API 执行以下操作:

  1. 获取条目(条目1)
  2. 使用条目 1 中字段的数据查找另一个条目 (条目 2)
  3. 使用条目 2 中的数据更新条目 1

我的代码如下所示:

client.getSpace("xxxxxxxx").then(function(space){
  space.getEntries({
    "content_type": "xxxxxxxx",
    "sys.id": "2KEZYJOgDSeQMCQIE0Oo88",
    "limit": 1
  }).then(function(places){

    //search for relevant category entry
    space.getEntries({
      "content_type": contentType.category,
      "sys.id": places[0].fields.category["en-GB"],
      "limit": 1
    }).then(function(category){

      //update place object
      places[0].fields.categoryNew = {
        "en-GB": [ 
          { sys: { type: "Link", linkType: "Entry", id: category[0].sys.id } } 
        ]
      };        

      //update place
      request({
        method: 'PUT',
        url: 'https://api.contentful.com/spaces/xxxxxxxx/entries/' + places[0].sys.id,
        headers: {
          'Authorization': 'Bearer xxxxxxxx',
          'Content-Type': 'application/vnd.contentful.management.v1+json',
          'X-Contentful-Content-Type': 'xxxxxxxx'
        },
        body: JSON.stringify({fields:places[0].fields}) …
Run Code Online (Sandbox Code Playgroud)

javascript api json node.js contentful

4
推荐指数
1
解决办法
3661
查看次数

标签 统计

api ×1

contentful ×1

javascript ×1

json ×1

node.js ×1