4

Contentful のコンテンツ管理 API を使用して、次のことを試みています。

  1. エントリーを取得する (entry1)
  2. entry1 のフィールドのデータを使用して、別のエントリ (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 は正常に機能しますが、元のエントリを更新する最後の手順では、次のエラーが返され続けます。

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

これを止めるにはどうすればよいですか?番号を手動で更新するなど、考えられるすべてのことを試しましたが、更新すると、提供したデータsys.versionが無視されるようです。sys

4

1 に答える 1

3

http://docs.contentfulcma.apiary.io/#introduction/resource-idsおよび「更新とバージョンのロック」というタイトルのセクションを参照してください。

PUT リクエストで、バージョンを「X-Contentful-Version」というヘッダー パラメータとして渡す必要があります。

于 2015-10-13T17:03:26.923 に答える