获取“您发送的正文包含未知密钥”尝试创建内容条目时

问题描述

我用两个字段创建了一个有争议的模型“ User”:

当我尝试使用以下参数通过内容管理API创建新条目时:

Headers:
X-Contentful-Content-Type : user
Content-Type : application/vnd.contentful.management.v1+json

Method
PUT

URL
https://api.contentful.com/spaces/qilo7tiaixh8/environments/entries/

Body:    
    {
        "id":"whatever","email": "peter@petervukovic.com"
    }

我收到以下错误

    {
        "requestId": "2849bbcd7ee0486bb36b47927071f37b","sys": {
            "type": "Error","id": "UnkNownKey"
        },"message": "The body you sent contains an unkNown key.","details": {
            "errors": [
                {
                    "keys": [
                        "id","email"
                    ]
                }
            ]
        }
    }

我不知道我在做什么错,因为official documentation中的示例没有帮助(他们假设我没有使用多语言内容)并且没有调试提示

解决方法

内容丰富的DevRel。 ?

我刚刚尝试过,下面的CURL在user内容类型上为我工作,该内容类型定义了title字段。

curl --include \
     --request PUT \
     --header 'Authorization: Bearer ...' \
     --header 'Content-Type: application/vnd.contentful.management.v1+json' \
     --header 'X-Contentful-Content-Type: user' \
     --data-binary '{
       "fields": {
         "title": {
           "en-US": "Hello Test"
         }
       }
     }' \
     https://api.contentful.com/spaces/.../environments/master/entries/\test-1

您似乎缺少将fields属性包含在有效负载中的功能。关于本地化部分,我认为有必要为您的字段值提供语言环境。因此,在我的示例中,en-US是默认值,它是必需的。

要使用PUT,您必须定义或提供条目ID

要创建条目而不传递和定义ID,请查看Entry collection中的文档。

curl --include \
     --request POST \
     --header 'Authorization: Bearer ...' \
     --header 'Content-Type: application/vnd.contentful.management.v1+json' \
     --header 'X-Contentful-Content-Type: user' \
     --data-binary '{
       "fields": {
         "title": {
           "en-US": "Hello Test 2"
         }
       }
     }' \
     https://api.contentful.com/spaces/.../environments/master/entries/