Contentful logo

Contentful Community

How can I create an entry via API that has rich text field?

Hey, I’m curious, I’m having trouble creating an entry with a rich text field via API, does someone have some documentation or library on how can I convert a WYSIWYG editor content into a rich text format? I’m trying to build a form that allows my users to suggest content that will be pushed as a draft entry into contentful.

Hi Alon,

A good starting point for Rich Text would be https://www.contentful.com/developers/docs/concepts/rich-text/

You can of course create some Rich Text document via the Contentful web app and look at the entry’s plain JSON to see how the corresponding Rich Text would look like.

Best,
Daniel

Base on the example here the format is different from the example here. so I am not able to send the payload.

It will be more useful to have an example payload for all the fields available added to the github or for now just paste an example of how the structure for the rich text should be.

Thanks,
Esteban

I found a way to send the data, here is the example for createEntry:

		environment.createEntry('<content_type>', {
			fields: {
				'<field_name>': {
					'<language>': {
                        content: [
                            {
                                nodeType:"paragraph",
                                data: {},
                                content: [
                                    {
                                        value: "lorem ...",
                                        nodeType:"text",
                                        marks: [],
                                        data: {}
                                    }
                                ]
                            }
                        ],
                        data: {},
						nodeType: 'document'
					}
				}
			}
		})

I hope it is helpful.

Esteban