During the development of WooCommerce 2.1 (Back in Feb 2014) we knew that one day WordPress would have it’s own REST API, but the demand was so great for such a thing in WooCommerce we had to roll our own.
We’ve learned a lot from this process and our API is now widely used, but given recent developments surrounding the actual WordPress REST API, and since it is now part of WordPress core (since version 4.4) we started work to replace ours with what is available in WordPress.
2.6 will contain this new API, and will require WordPress 4.4 or higher.
What API changes should we expect?
The first change is with endpoints, in our current API you can fetch your orders using:
The new REST API will instead use:
Note that we use the
wc/v1/, since it’s not our API v4, but a completely new REST API, and our first based on the WP REST API hence v1.
We had to make some changes to the data we offer through the API to reflect recent developments and changes in WC core, and to try to offer consistent data, but the largest and most notable change is the way that data is sent and received with the new API.
For example, in the current REST API, we use the format:
But using the WP REST API we had to change this to:
The WP REST API uses schemas to describe and self-document endpoints, so it’s easy to know what is needed to create an object or what to expect while fetching something. As an example, this would get the schema for
This returns the following response:
We will be offering our own documentation and updated API wrappers as well before the final release of 2.6, but as you can see, it’s very simple to query and inspect any endpoint if you want to use the new API now.
Things we won’t be changing…
Some things remain the same even with the introduction of this new API:
- All WC REST API keys can be used in the WP REST API.
- Our Authentication Endpoint still works like before.
- Webhooks will continue to work.
- Our entire current REST API will still be available.
Regarding authentication, it’s still possible to use Basic Auth and oAuth1.0a using current WC API keys, and we don’t have plans to remove our API key system, so this should make it easy to migrate Apps using our APIs. The new API allows more ways to authenticate users though; it supports all of the WP REST API authentication methods.
What API should I use in my Apps?
If possible, we recommend using the new WP based API as soon as it’s launched. It’s simpler, easier to use, and it makes use of WordPress core as much as possible.
We don’t have plans to deprecate our current REST API just yet, at least not before WooCommerce 3.0, so everyone has ample time to migrate to the new REST API once released.
To try the new API you can grab master branch from Github, or wait for beta 1 to be tagged within the next week or so. If you have feedback or find issues in the new API, please report them on Github with label “[API]”.