0
我試圖做的Contentful內容管理API如下:Contentful API返回「版本不匹配」的條目更新
- 獲得入門(取值範)
- 查找另一個條目(ENTRY2)使用的數據來自現場的取值範
- 取值範更新與數據從ENTRY2
我的代碼如下所示:
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
數據。