【问题标题】:Importing Data to Contentful programatically from a json file从 json 文件以编程方式将数据导入 Contentful
【发布时间】:2020-08-06 03:46:33
【问题描述】:

我正在尝试以编程方式将一些数据导入内容:

我正在关注文档here

并在我的集成终端中运行命令

contentful space import --config config.json  

配置文件在哪里

{
  "spaceId": "abc123",
  "managementToken": "112323132321adfWWExample",
  "contentFile": "./dataToImport.json"
}

而dataToImport.json文件是

{
  "data": [
    {
      "address": "11234 New York City"
    },
    {
      "address": "1212 New York City"
    }
  ]
}

问题是我不明白我的 dataToImport.json 应该是什么格式,以及这个文件或我的配置文件中缺少什么,因此 .json 文件中的地址数组被添加为 新条目 在下面的屏幕截图中显示的 Contentful UI 中已创建的内容模型

我没有指定要输入的数据的内容模型,所以我认为这是一个问题,我不知道我是如何做到的。一个例子或回购将极大地帮助我

【问题讨论】:

    标签: api import contentful


    【解决方案1】:

    您可以导入的数据类型如下:in their documentation

    如果您要导入内容类型的新内容,则您的 json 顶层应该显示“条目”而不是数据。

    这是根据他们提供的教程的内容模型的博客文章示例。 我唯一没有解决的问题是用户 ID 在哪里:D 所以我替换了他们教程中也提供的内容类型“人”之一(我认为它称为 Gatsby Starter)

    {"entries": [
    {
      "sys": {
        "space": {
          "sys": {
            "type": "Link",
            "linkType": "Space",
            "id": "theSpaceIdToReceiveYourImport"
          }
        },    
        "type": "Entry",
        "createdAt": "2019-04-17T00:56:24.722Z",
        "updatedAt": "2019-04-27T09:11:56.769Z",
        "environment": {
          "sys": {
            "id": "master",
            "type": "Link",
            "linkType": "Environment"
          }
        },
        "publishedVersion": 149, -- these are not compulsory, you can skip 
        "publishedAt": "2019-04-27T09:11:56.769Z", --  you can skip
        "firstPublishedAt": "2019-04-17T00:56:28.525Z", --  you can skip
        "publishedCounter": 3, --  you can skip
        "version": 150,
        "publishedBy": { -- this is an example of a linked content
          "sys": {
            "type": "Link",
            "linkType": "person",
            "id": "personId"
          }
        },
        "contentType": {
          "sys": {
            "type": "Link",
            "linkType": "ContentType",
            "id": "blogPost" -- here should be your content type 'RealtorProperties'
          }
        }
      },
      "fields": { -- here should go your content type fields, i can't see it in your post
                "title": {
                    "en-US": "Test 1"
                },
                "slug": {
                    "en-US": "Test-1"
                },
                
                "description": {
                    "en-US": "some description"
                },
                "body": {
                    "en-US": "some body..."
                },
               
                "publishDate": {
                    "en-US": "2016-12-19"
                },  
                "heroImage": { -- another example of a linked content
                  "en-US": {
                    "sys": {
                      "type": "Link",
                      "linkType": "Asset",
                      "id": "idOfTHisImage"
                    }
                    }
                }
      }
    },
    --another entry, ...]}
    

    【讨论】:

      【解决方案2】:

      看看这个repo。我也在试图弄清楚这一点。看起来有很多字段需要包含在 json 文件中。我希望有一个简单的解决方案,但似乎您(实际上我也是)需要创建脚本来将您的 json 文件“转换”为内容内容可以读取和导入的数据。 如果我发现更好的东西,我会告诉你的。

      【讨论】:

        猜你喜欢
        • 2011-03-25
        • 1970-01-01
        • 2023-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-20
        • 1970-01-01
        • 2019-06-10
        相关资源
        最近更新 更多