As you might know if you follow WordPress developer news, the WordPress REST API content endpoints are slated to be merged into WordPress core in the upcoming 4.7 release. These endpoints cover basic WordPress features (posts, pages, custom post types, revisions, media, comments, taxonomies, users, and settings). While they have also been available via the WP REST API plugin for some time, this is the latest step in a multi-year project to bring a modern, RESTful API to all WordPress installations.
We are pleased to announce that WordPress.com is now running the WordPress REST infrastructure alongside our pre-existing v1 API. Additionally, we have made the new content endpoints available now so that developers can try them out, provide feedback and drive wider adoption of the new API.
The success metrics for this feature, detailed here, focus on increasing utilization of the new API in plugins, themes, third-party clients and within WordPress core itself. This new API represents the future of WordPress and WordPress.com, and we want to make it as solid as we can. We encourage all WordPress developers to take it for a spin and let us know what you think!
Using the New API
The WordPress REST API is available on WordPress.com with the following base URL: https://public-api.wordpress.com/wp/v2/. This new API is backwards-incompatible with the v1 API, which we have no plans to deprecate at this time.
Going forward, we encourage developers to write new code against the v2 API whenever possible. This has the added benefit of making your applications able to run against both WordPress.com and self-hosted WordPress sites.
To make testing and exploration easier, we’ve also updated our API console to support both versions of our API. You can switch API versions using the dropdown toggle in the upper left:
Once you’ve selected the WP REST API, you can view and select endpoints and make authenticated requests just as in the previous version:
For self-hosted sites running the Jetpack plugin, we expect read requests to work (but you must be running at least Jetpack version 4.3.2). Write requests to Jetpack sites do not work yet, since this will require the site to be running the content endpoints and a future version of the Jetpack plugin that supports them.
In addition, a few endpoints are restricted or disabled on WordPress.com, generally for parity with our v1 API. A few examples:
- Listing and retrieving media items requires authentication
- Listing and retrieving user info requires authentication
- Endpoints to create/edit/delete users are disabled
- Updating the email and URL settings via the settings endpoint is disabled
Here are some examples that could serve as a starting point. If you build your own, please share it in the comments!
- Our REST API console: https://github.com/Automattic/rest-api-console2 (supports WordPress.com sites)
- The in-progress rewrite of our REST API console: https://github.com/Automattic/wp-api-console (supports both WordPress.com and self-hosted sites)
- A simple “secret notepad” backed by the REST API (supports both WordPress.com and self-hosted sites): https://github.com/nylen/wp-rest-notepad
- A simple command-line todo list app backed by the REST API (supports WordPress.com sites): https://github.com/timmyc/wptodo
- A proof-of-concept of Quick Draft using the REST API (for self-hosted sites): https://core.trac.wordpress.org/ticket/38342
- A proof-of-concept of Press This using the REST API (for self-hosted sites): https://core.trac.wordpress.org/ticket/38343
- We’re also using custom API endpoints built on the REST infrastructure in several places, for example in our Jetpack and WooCommerce plugins and on WordPress.com. Since we enabled them in early 2016, our custom WordPress.com endpoints have served over 200 million requests.
How to Provide Feedback
- There are weekly developer chats in the WordPress Slack channel. More info can be found on the sidebar of https://make.wordpress.org/core/.
- WordPress core uses Trac to track bugs and open issues. The master ticket for this feature is here: https://core.trac.wordpress.org/ticket/38373; you can also search for an existing REST API issue or open a new one.
- Drop a comment on this post, or contact our developer support team, especially if you find a problem or inconsistency specific to the WordPress.com version of the API.