4

我正在使用 Contentful 管理节点模块和 Javascript 进行 Contentful 项目。我正在尝试在包含新条目的条目中创建引用。

我在浏览器控制台中收到以下消息:

     Uncaught (in promise) Error: {
     "request": {
"url": "https://api.contentful.com:443/spaces/59mi8sr8zemv/entries/2Bxpz2RgA4AQImQOssey8w/published",
"headers": {
  "Accept": "application/json, text/plain, */*",
  "Content-Type": "application/vnd.contentful.management.v1+json",
  "X-Contentful-User-Agent": "contentful-management.js/1.3.1",
  "Authorization": "Bearer <my management-api key>",
  "X-Contentful-Version": 373
  },
   "method": "put",
   "payloadData": null
    },
    "status": 422,
    "statusText": "Unprocessable Entity",
    "requestId": "d00dde60cd564a8db84da90cd671b19f",
    "message": "Validation error",
    "details": {
    "errors": [
    {
    "name": "notResolvable",
    "link": {
      "id": "2Yfc2H8q9OSoOccGcSg4aU",
      "linkType": "Entry",
      "type": "Link"
    },
    "path": [
      "fields",
      "link",
      "en-US",
      7
    ]
  }
]
}
}
 at errorHandler (main-addTrack.bundle.js:3096)

当我查看内容丰富的网络应用程序时,新条目就在那里,但保存为草稿。我尝试添加条目的条目表示需要更新。

这是我用来创建和更新新条目的功能。

    function publishTrack(){
        //-- Creates the new track in events, with ref to korrekt date
        client.getSpace(<my_spaceId>)
            .then((space) => {
            space.createEntry('events', newTrack)
                .then( event => {

                eventID = event.sys.id;

               (entry) => entry.publish()

                //This function is gets the entry of choosen date
                space.getEntry(dateId)
                    .then((entry) => {

                    //Gets the ID from the newly created event
                    var newId = {sys: {
                        id: eventID,
                        linkType: "Entry",
                        type:"Link"
                    }}

                    //Creates a reference field in dates for show & do
                    entry.fields.link["en-US"].push(newId)

                    //update the event
                    return entry.update()
                    space.getEntry(eventID)
                    .then ((eventID) => entry.publish())

                })
                  space.getEntry(dateId)
                    .then ((entry) => entry.publish());

            })

            publishModal.style.display = 'block';
            publishModal.style.opacity = '1';
            publishModal.style.pointerEvents = 'auto';
            publishModal.style.zIndex = '99999';

        })

    }//end publish track

请为任何错误道歉,这是我在stackowerflow上的第一篇文章。

4

2 回答 2

2

看起来您的参考条目之一无法专门解析 at fields.link["en-US"][7](请注意错误消息中的“路径”属性),请确保在创建事件之前创建并发布它。

于 2017-06-06T11:38:25.207 回答
1

在后台,您正在执行 HTTP PUT 请求。这意味着用新资源替换现有资源。但是,您的有效负载是空的:

"payloadData": null

并且您收到用户错误 4xx(特别是 422),这意味着您发送的有效负载无效。所以这意味着 Contentful 不接受将该值设置为 null。但是,这似乎有点奇怪,因为您要添加newId的不是空值。

您尝试用 PUT 替换的资源是/fields/link/en-US/7. 可能是某些中间资源不存在(例如 、/fields/fields/link/fields/link/en-US,并且子资源上的 PUT 未由 Contentful 处理。

于 2017-06-06T13:22:20.900 回答