Contentful logo

Contentful Community

Troubles trying to create entry

Hello there.

I am following this documentation and I am having troubles to create an entry.

The response status I am getting is a 404 Not found with this body

{
  "sys": {
    "type": "Error",
    "id": "NotFound"
  },
  "message": "The resource could not be found.",
  "requestId": "fd52263e19f9d39a18296d8faebc69ba"
}

By the way, I am able to get the entries from a space so I guess that the {space_id}, the {environment_id} and the authorization param with the token are right.

This is why I guess the problem has to do with the X-Contentful-Content-Type. In the documentation example it is set as 2PqfXUJwE8qSYKuM0U6w8M but I can not find whre to get this value for my query.

Hi @ramonmorcillocascale, yes the X-Contentful-Content-Type is needed and has to match the actual structure of your content-type.

To check the id, try to look into the Web App, “Content Model” > [your Content type] > “JSON preview” and use the sys.id value. Usually that value is self-explanatory based on the name of your content-type.

Hi @Alma , Thanks for the answer and the help!

I have tried the request again with the value you told me but it is still not working. Here is the JSON from the Content-Type:

{
  "name": "Entity - Product",
  "description": "",
  "displayField": "id",
  "fields": [
    {
      "id": "id",
      "name": "id",
      "type": "Symbol",
      "localized": false,
      "required": true,
      "validations": [
        {
          "unique": true
        }
      ],
      "disabled": false,
      "omitted": false
    },
    {
      "id": "pageMetadata",
      "name": "page metadata",
      "type": "Link",
      "localized": false,
      "required": true,
      "validations": [
        {
          "linkContentType": [
            "page"
          ],
          "message": "You must define the page info"
        }
      ],
      "disabled": false,
      "omitted": false,
      "linkType": "Entry"
    },
    {
      "id": "backgroundImage",
      "name": "background image",
      "type": "Link",
      "localized": false,
      "required": true,
      "validations": [],
      "disabled": false,
      "omitted": false,
      "linkType": "Asset"
    },
    {
      "id": "image",
      "name": "image",
      "type": "Link",
      "localized": false,
      "required": true,
      "validations": [],
      "disabled": false,
      "omitted": false,
      "linkType": "Asset"
    },
    {
      "id": "title",
      "name": "title",
      "type": "Symbol",
      "localized": true,
      "required": true,
      "validations": [],
      "disabled": false,
      "omitted": false
    },
    {
      "id": "content",
      "name": "content",
      "type": "RichText",
      "localized": true,
      "required": true,
      "validations": [
        {
          "nodes": {}
        }
      ],
      "disabled": false,
      "omitted": false
    },
    {
      "id": "whatsIn",
      "name": "whats in",
      "type": "Link",
      "localized": false,
      "required": true,
      "validations": [
        {
          "linkContentType": [
            "whatsIn"
          ]
        }
      ],
      "disabled": false,
      "omitted": false,
      "linkType": "Entry"
    },
    {
      "id": "relatedProducts",
      "name": "relatedProducts",
      "type": "Link",
      "localized": false,
      "required": true,
      "validations": [
        {
          "linkContentType": [
            "productsSection"
          ]
        }
      ],
      "disabled": false,
      "omitted": false,
      "linkType": "Entry"
    }
  ],
  "sys": {
    "space": {
      "sys": {
        "type": "Link",
        "linkType": "Space",
        "id": "hgk81q2huere"
      }
    },
    "id": "entityProduct",
    "type": "ContentType",
    "createdAt": "2020-06-18T09:46:29.156Z",
    "updatedAt": "2020-06-18T09:46:29.586Z",
    "environment": {
      "sys": {
        "id": "master",
        "type": "Link",
        "linkType": "Environment"
      }
    },
    "publishedVersion": 1,
    "publishedAt": "2020-06-18T09:46:29.586Z",
    "firstPublishedAt": "2020-06-18T09:46:29.586Z",
    "createdBy": {
      "sys": {
        "type": "Link",
        "linkType": "User",
        "id": "2WqJ9wiNgDQQeY0oUpLgZy"
      }
    },
    "updatedBy": {
      "sys": {
        "type": "Link",
        "linkType": "User",
        "id": "2WqJ9wiNgDQQeY0oUpLgZy"
      }
    },
    "publishedCounter": 1,
    "version": 2,
    "publishedBy": {
      "sys": {
        "type": "Link",
        "linkType": "User",
        "id": "2WqJ9wiNgDQQeY0oUpLgZy"
      }
    }
  }
}

And the values I have tried are these ones:
Screenshot 2020-07-06 at 13.33.18
And the response I get is still this one:

{
  "sys": {
    "type": "Error",
    "id": "NotFound"
  },
  "message": "The resource could not be found.",
  "requestId": "a9687cf515f5792088f8bf9b531ebab1"
}

Could you please tell me if I am missing something or if I have used the wrong value?

The main query you were performing was:
POST /spaces/hgk81q2huere/environments/master/entries/entityProduct

And it needs to be modified to:
POST /spaces/{space_id}/environments/{environment_id}/entries
with header ‘X-Contentful-Content-Type: entityProduct’