contentful / contentful-management.js

JavaScript library for Contentful's Management API (node & browser)
https://contentful.github.io/contentful-management.js
MIT License
264 stars 97 forks source link

Contentful API error when creating rich text with embdedding entities #2252

Closed asilyin closed 3 months ago

asilyin commented 3 months ago

Contentful API error when creating rich text with embdedding entities SpaceID: xchjjphyj85t

Request:

{
    "fields": {
        "simpleTextField1": {
            "en-US": "Test Value"
        },
        "richTextField1": {
            "en-US": {
                "nodeType": "document",
                "data": {},
                "content": [{
                        "nodeType": "paragraph",
                        "data": {},
                        "content": [{
                                "nodeType": "text",
                                "value": "Hello\n",
                                "marks": [],
                                "data": {}
                            }, {
                                "nodeType": "text",
                                "value": "World\nTest",
                                "marks": [{
                                        "type": "bold"
                                    }
                                ],
                                "data": {}
                            }
                        ]
                    }, {
                        "nodeType": "embedded-entry-inline",
                        "data": {
                            "target": {
                                "sys": {
                                    "id": "2cI1LQBTcCOhbOXYMUhC4h",
                                    "type": "Link",
                                    "linkType": "Entry"
                                }
                            }
                        },
                        "content": []
                    }, {
                        "nodeType": "paragraph",
                        "data": {},
                        "content": [{
                                "nodeType": "text",
                                "value": "Content 2",
                                "marks": [{
                                        "type": "bold"
                                    }
                                ],
                                "data": {}
                            }
                        ]
                    }
                ]
            }
        }
    },
    "metadata": null
}
`

Error:

{
    "name": "in",
    "details": "Value must be one of expected values",
    "path": [
      "fields",
      "richTextField1",
      "en-US",
      "content",
      1,
      "nodeType"
    ],
    "value": "embedded-entry-inline",
    "expected": [
      "blockquote",
      "embedded-asset-block",
      "embedded-entry-block",
      "embedded-resource-block",
      "heading-1",
      "heading-2",
      "heading-3",
      "heading-4",
      "heading-5",
      "heading-6",
      "hr",
      "ordered-list",
      "paragraph",
      "table",
      "unordered-list"
    ]
  }
]

I am using dotnet API client, but the error seems to be on Server, not on Client

z0al commented 3 months ago

Hi @asilyin thanks for the report.

Taking a closer look at your input it seems that the embedded-entry-inline isn't inside a paragraph which isn't supported. Inline elements e.g. hyperlinks, embedded entry inline ..etc must be inside a paragraph element. If you want to have an embedded entry at the root level it has to be of type embedded-entry-block.

So you have two options to fix the issue:

  1. Either wrap or move the embedded-entry-inline with/to a paragraph element
  2. Change the type to be embedded-entry-block

image

I hope that helps.