• About RestAPI and posts written via Gutenberg

    hello. I run a multilingual website and I want to publish a post from site A to site B using Rest API.

    Rest API works fine, but the problem is that the posts are always published in the classic editor, even though both websites use Gutenberg.

    Is there any way to make the Rest API recognise Gutenberg blocks when publishing posts?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Felipe Santos

    (@foosantos)

    Hi there,

    Does that also happen even if you add the posts using the block structure?

    For instance:

    <!-- wp:paragraph -->
    <p>This is a paragraph block.</p>
    <!-- /wp:paragraph -->
    Thread Starter cheonmu

    (@cheonmu)

    hello.

    Yes. The same problem occurs when using a block structure. The Rest API does not include Gutenberg’s block information in the api.

    You can see my API here https://seototo.net/wp-json/wp/v2/posts

        "content": {
          "rendered": "\n\u003Cp\u003EThis is a paragraph block.\u003C/p\u003E\n",
          "protected": False
        }

    But i can use html tag that classic editor can support, such as P tags. I can switch to Gutenberg from the classic editor with just push of a button.

    However, The problem occur when we use Gutenberg blocks, which are not supported by the Classic Editor.

    The classic editor doesn’t recognise blocks like Toc, Gallery, FAQ, etc. so when i publish a post via the Rest API, those parts won’t be published.

    I’m not sure if this is exactly a Rest API issue or a Gutenberg issue.

    What I found is that when publishing via the Rest API, the post is published in the classic editor as it does not include Gutenberg block information, and any blocks that are not supported by the classic editor are not displayed.

    Hi @cheonmu Is it possible that the classic editor is the default editor? Do you have the classic editor plugin installed? If yes, you might need to test your calls with different settings.
    See Screenshot of the Classic Editor plugin

    The “raw” markup of the post, which will contain the Gutenberg HTML comments, is available if you access the post with the _context=edit query parameter . This requires API authentication, but you can easily see the shape of the data if you run a test query in the JS console within the block editor:

    wp.apiFetch( {
        path: '/wp/v2/posts&posts_per_page=1&_context=edit'
    } ).then( result => console.log( result[0] ) );

    If you fetch with the “edit” context, you will get the post.content.raw string, which should be interpreted as blocks by the second site.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘About RestAPI and posts written via Gutenberg’ is closed to new replies.