A Beginner Guide to Woocommerce REST API

Home / Blog / A Beginner Guide to Woocommerce REST API

Woocommerce is by far the most popular plugin used to run online stores on a Wordpress site. You can easily create and configure your store, add your products, and start selling them online. The multiple plugins available help you customize your store and build a specific flow, based on your needs.

The woocommerce plugin comes with a nice feature, the woocommerce REST API, which help to extend the functionalities furthermore.

What is Woocommerce Rest API

The woocommerce Rest API allows you to access the data of your store outside of Wordpress. It is an interface used to allow woocommerce stores to interact with other applications, over the internet. The interface will define a set of endpoints ( similar to a web address) we can use to make various requests ( display / GET, create / POST , update / PUT, delete / DELETE products for example)

How to use Woocommerce Rest API

The woocommerce Rest API should be enabled by default. To be able to use it though, you need to generate a set of API keys. This set of keys will be used to authenticate and authorize the requests when calling the endpoints.

Generate API keys

The procedure to generate the API keys is fairly simple, and it is shown there. Below is a quick summary of the procedure:

  1. Go to: WooCommerce > Settings > Advanced > REST API.
  2. Select Add Key. An interface will be displayed.
  3. Add a Description (optional).
  4. Select the User you would like to generate a key for in the dropdown.
  5. Select a level of access for this API key — Read access, Write access or Read/Write access.
  6. Select Generate API Key, and WooCommerce creates API keys for that user.

Note that once you leave the page, the keys will be masked if you want to see them later. Make sure to copy them before navigating away ( A description can be important to remember the purpose of those keys).

Simple usage of the woocommerce Rest API

To validate the Rest API is functional, we need a tool to call our requests and display the results. We will use Postman, a popular platform used by the developers to buiild and validate API requests.

Let's try to display a list of woocommerce products. The following GET method is used to obtain the list of products: https://yourwebsite.com/wp-json/v3/products. The API is sent over an HTTP request, and the keys we define earlier need to be set in the header of the request.

product list woocommerce api

The request returns 200 OK, which means the call was successful. In the response we obtain the list of products in special format called json.

Various other practical operations can be made via the Rest calls like creating a product, updating the info of a product, display the orders, update order status,...

Use cases for the Rest API

The woocommerce Rest API allows to interact with a woocommerce store outside of the wordpress admin panel. This feature unleashes a lot of possibilities for a store owner that can be used to simplify some operations.

Custom admin interface

Like shown i the example, we can get the list of woocommerce items, and display them in a custom interface. If you don't like the default woocommerce dashboard, or just need a dashboard with more options, it is definitely a solution to explore.

Mobile e-commerce application

We can also leverage the woocommerce Rest API to build a mobile e-commerce application. A strong analysis needs to be done to determine if a mobile application is viable for the business. If it is the case, then the Rest APIs can be used to display the products and handle the order creation.

Integration with other systems

A more advanced use of the APIs is to handle the data transfer between 2 systems. For example, if you use a software like quickbooks online for accounting or invoicing purpose, you can automate the process of adding a new sell record in the software. When an order is complete on te website, a new line is automatically added in quickbooks. No need to do it manually, or use excel documents to export/import the data.

As you can see, the Rest API are quite powerful and can help us achieve different tasks. I actually used the woocommerce rest API to build a mobile application which help store owners to manage woocommerce from their mobile device.

If you have a project in mind, and you also want to leverage the woccomerce Rest API, please reach out to us. We will help you build and develop your solution.

Categories: woocommerce API


No Comment

Leave a reply

*Required for comment verification