内容丰富的API在条目更新时返回“版本不匹配" [英] Contentful API returning 'version mismatch' on entry update

查看:86
本文介绍了内容丰富的API在条目更新时返回“版本不匹配"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Content Management API进行以下操作:

I'm attempting to do the following with the Content Management API for Contentful:

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

我的代码如下:

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})
      }, function (error, response, body) {
        console.log(body);
      });

    });


  });
});

第1步和第2步工作正常,但最后一步(更新原始条目)不断返回以下错误:

Steps 1 and 2 work fine but the final step, updating the original entry, keeps returning the following error:

Response: {
  "sys": {
    "type": "Error",
    "id": "VersionMismatch"
  },
  "requestId": "content-api:2PSSF6RtpSs2YyaaisK2wc"
}

如何阻止这种情况发生?我已经尝试了所有可以想到的方法,包括手动更新sys.version数字,但是在更新时,它似乎忽略了我提供的任何sys数据.

How do I stop this happening? I've tried everything I can think of including manually updating the sys.version number, but when updating it seems to ignore any sys data I provide.

推荐答案

请参阅 http ://docs.contentfulcma.apiary.io/#introduction/resource-ids 和标题为"更新和版本锁定"

您需要通过PUT请求将版本作为标题参数"X-Contentful-Version"传递.

You need to pass the version as a header parameter called "X-Contentful-Version" with the PUT request.

这篇关于内容丰富的API在条目更新时返回“版本不匹配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆