我正在尝试使用针对Contentful的Content Management API执行以下操作:
我的代码如下所示:
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工作正常,但最后一步,更新原始条目,不断返回以下错误:
Response: {
"sys": {
"type": "Error",
"id": "VersionMismatch"
},
"requestId": "content-api:2PSSF6RtpSs2YyaaisK2wc"
}
如何阻止这种情况发生?我已经尝试了我能想到的所有内容,包括手动更新sys.version
号码,但在更新时似乎忽略了我提供的任何sys
数据。
答案 0 :(得分:-1)
请参阅http://docs.contentfulcma.apiary.io/#introduction/resource-ids以及标题为“更新和版本锁定”
的部分您需要使用PUT请求将版本作为名为“X-Contentful-Version”的标头参数传递。