Fill fields of type Rich text (Blocks) via REST API

System Information
  • Strapi Version: 4.20.1
  • Operating System:
  • Database: SQLite
  • Node Version: 20
  • NPM Version:
  • Yarn Version:

Hi, I have a content type that contains a field of type rich text (block). The query via REST API works and returns the information nested (type: paragraph, children etc.).

2024-02-20_15-26-35

(My field is called “content”)

Is it possible to fill this field via REST API POST request? If so, how must my JSON be formatted so that the field is filled with a value?

In my previous tests, only the “title” field was ever filled, “content” remains empty…

2 Likes

The only person I saw speaking to this was:

Sending blocks data back and forth with your own editor appears to be a difficult chore atm.

2 Likes

@Siddi, my first bet would be to update your data object to match the shape outlined here e.g.

data: {
  title,
  content: [
     {
      "type": "paragraph",
      "children": [
        {
          "text": "test",
          "type": "text"
        }
      ]
    }
  ]
}

I feel like that should at least save one node inside of the content for the rich-text block editor. The sample response provided should include most, if not all, of the blocks that can be output via the editor currently :thought_balloon:

As @cpres said, it can be tricky to work with as you need to ensure the provided object adheres to the expected shape. If you’re still working on it and run into trouble feel free to drop an update with the issues you’re encountering :raised_hands:

1 Like

Thank you very much, that worked. I think the format must be exactly the same as what you get back with an API query.

1 Like