Skip to content

Block Data API plugin

The Block Data API is a REST API for retrieving block editor posts structured as JSON or GraphQL. Though it is primarily designed for use in decoupled WordPress, the Block Data API can be used anywhere a developer needs to represent block markup as structured data.

The Block Data API plugin has built-in integration for the official WordPress REST API, and can be configured to integrate with the WPGraphQL plugin to provide a GraphQL API

The Block Data API plugin is authored and maintained by WordPress VIP, and made available to all WordPress sites by VIP MU plugins. Detailed instructions for using the plugin are located in the plugin’s GitHub repository.

This plugin is in active development, and the API endpoint will be incrementally versioned each time major changes are made to the structure and content of the output. Previous API endpoint versions will remain accessible and stable for backward compatibility.

Enable the Block Data API plugin

Enable the Block Data API plugin supplied by VIP MU plugins by adding the method shown below to an application’s plugin-loader.php. Create a new plugin-loader.php in an application’s client-mu-plugins directory if it does not yet exist.

client-mu-plugins/plugin-loader.php
\Automattic\VIP\Integrations\activate( 'block-data-api' );

To confirm that the Block Data API plugin is successfully enabled, make a request to the API endpoint: /wp-json/vip-block-data-api/v1/posts/<post_id>/blocks.

For example, a site with the Site Address URL example.com that has a valid post ID 1234 can test the Block Data API endpoint with the URL: example.com/wp-json/vip-block-data-api/v1/posts/1234/blocks.

Caching behavior

By default—when enabled on a VIP Platform-hosted site—requests to the Block Data API with a 200 HTTP status response are cached for 1 minute. For performance reasons, it is strongly recommended not to lower the TTL to less than 1 minute.

Authenticated requests that are made to the Block Data API will bypass the cache entirely. Because of this, use caution when utilizing the REST permissions filter.

Last updated: January 22, 2024

Relevant to

  • Node.js
  • WordPress