Contentful のコンテンツ管理 API を使用して、次のことを試みています。
- エントリーを取得する (entry1)
- entry1 のフィールドのデータを使用して、別のエントリ (entry2) を検索します。
- 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 は正常に機能しますが、元のエントリを更新する最後の手順では、次のエラーが返され続けます。
Response: {
"sys": {
"type": "Error",
"id": "VersionMismatch"
},
"requestId": "content-api:2PSSF6RtpSs2YyaaisK2wc"
}
これを止めるにはどうすればよいですか?番号を手動で更新するなど、考えられるすべてのことを試しましたが、更新すると、提供したデータsys.version
が無視されるようです。sys