0

I have created a contentful model called "User" with two fields:

  • id - text, unique, required
  • email - text, optional

When I try to create a new entry via content management API using these parameters:

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"
    }

I get the following error:

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

I have no idea what I'm doing wrong as the examples in the official documentation aren't helpful (they assume multi-lingual content I'm not using) and there are no debugging hints.

pvukovic
  • 239
  • 1
  • 9

1 Answers1

0

Contentful DevRel here.

I just tried it and the following CURL works for me on a user content type that defines a title field.

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

It looks like you were missing to include the fields property in your payload. About the localization part, I think it's required to provide the locale for your field values. So in my example, en-US is the default value and it is required.

For using PUT you have to define or come up with an entry id.

To create an entry without passing and defining an id have a look at the docs in 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/
stefan judis
  • 3,416
  • 14
  • 22
  • I tried your example and unfortunately, I'm getting the same error: "The body you sent contains an unknown key." The key that is unknown this time is "en-US". I'm using Postman. – pvukovic Nov 10 '20 at 12:39
  • Hmm... What's your default locale then? This is copied and pasted from my terminal in a space with a `user` content type having a `title` short text field and the default locale `en-US`. – stefan judis Nov 10 '20 at 14:12
  • It's `en-US`. [Screenshot](https://prnt.sc/vgucty) – pvukovic Nov 10 '20 at 15:25
  • Hmm... Ja I don't know. Without seeing your Postman config I can not help further I think. Do the curl commands I pasted work for you? – stefan judis Nov 11 '20 at 08:40