0

我四处搜索并查看了所有 SDK 文档和 Contentful 的 API 文档,我很难理解如何在创建新条目时添加带有资产链接的媒体字段。我可以成功创建其他字段,但媒体字段应该是一个对象,但我不确定如何格式化,以便 Contentful 接受它。

const videoAsset = yield client.getAsset(assetID)

fields = {
  title: {
    "en-US": 'Title' //works
  },
  description: {
    "en-US": 'Description' //works
  },
  video: {
    "en-US": //contenful api wants an object, what does this object look like?
               //i have a published asset in videoAsset returned by client.getAsset()
  },
  team: {
    "en-US": 'Community' //works 
  },
}

const entryCreated = yield space.createEntry(action.payload.contentType, {
    fields: fields
})

当我说“作品”时,我的意思是我可以成功地创建一个出现在内容空间中的条目。

4

1 回答 1

2

我得到了它!

这个人没有做完全相同的事情,但格式方面的答案在这里:

https://github.com/contentful/contentful-management.js/issues/57

基本上该字段应如下所示:

const videoAsset = yield client.getAsset(assetID)

fields = {
  title: {
    "en-US": 'Title' //works
  },
  description: {
    "en-US": 'Description' //works
  },
  video: { 
    "en-US": {
       sys: {
         type: "Link", linkType: "Asset", id: assetID
       }
     }
  }, //this formatting works!
  team: {
    "en-US": 'Community' //works 
  },
}

const entryCreated = yield space.createEntry(action.payload.contentType, {
    fields: fields
})
于 2018-01-13T09:22:20.300 回答