Ultimate Guide on How to Use WooCommerce REST APIs Simplified 101

By: Published: October 12, 2021

WordPress is used by individuals and businesses as a Content Management System. It helps them create blogs and websites through which they can interact with their target audience. This is also good for the exchange of information between the website owner and the visitors. If you need to run an online business, you may need to develop an eCommerce store for your shop. Here, WooCommerce can help you get started with ease. WooCommerce makes this a reality for you by turning WordPress into an eCommerce store. 

Other than the basic functionality provided by WooCommerce, you can use a WooCommerce REST API to extend the functionality of your eCommerce store. It can help you to interact with data related to your eCommerce shop & perform operations such as reading, creating, updating, and deleting it. You can also use the API to make additional connections to your eCommerce store. Thus, the WooComerce REST API can help you to get more functionalities from your basic WooCommerce store.

In this article, we will be discussing how to use the WooCommerce REST API.

Table of Contents

Prerequisites

This is what you need:

  • A WordPress Website or Blog.

Understanding WooCommerce REST API

WooCommerce REST APIs
Image Source

The WooCommerce REST API is an interface that you can use to access your WooCommerce store from outside WordPress. It was designed to make it easy for WooCommerce stores on WordPress to interact with other websites and applications over the Internet. 

The functionality is managed via HTTP requests, and all HTTP requests are universally available. The HTTP protocols help WooCommerce websites to read, send, create, update, and delete service requests via the endpoints. The WooCommerce REST API can also understand directory-like URL structures. 

Thus, the WooCommerce REST API helps you to do everything offered by your WooCommerce admin area, remotely, that is, without having to log into your website manually. 

Using the WooCommerce REST API

In this section, we will be discussing how to use the WooCommerce REST API:

1) Enabling WooCommerce REST API Access

You should begin by enabling the WooCommerce API in WordPress admin. Follow the steps given below to do so:

Step 1: Log in to the backend of your WordPress website.

Step 2: Hover over “WooComerce”, select “Settings”, and then “Advanced”.

Step 3: Toggle the “Legacy API” tab and activate the “Enable the legacy REST API” button.

WooCommerce REST APIs - Legacy API
Image Source

The WooCommerce API is now enabled. 

2) Creating an API Key

Once the WooCommerce REST API has been enabled, you should create an API key. The generated key will then be used to authenticate your API requests. This will help the WooCommerce REST API to serve legitimate requests only. 

To generate an API key, follow the steps given below:

Step 1: Open the WordPress admin and click “REST API”. 

Step 2: Type the description and choose the user & permissions. 

Step 3: Click the “Generate API Key” button.

WooCommerce REST APIs - Generating API keys
Image Source

It’s recommended that you give the API, Read/Write access. This means that you will be able to read, create, update, and delete the WooCommerce data via the API. 

Upon clicking the “Generate API Key button, two alphanumeric strings will be generated, which are the Consumer Key and Consumer Secret. 

Copy the two keys to a safe place. You will need them when connecting to the WooCommerce REST API. The keys are processed by the PHP backend once a request is made. 

3) Downloading an API Client

Although the WooCommerce API has been enabled and the API key has been created, you need an API client to help you to make requests and view responses. The API keys will enable you to connect WooCommerce to your WordPress website via an API client

There are different API clients that you can choose, for example, Postman and Insomnia. These two will allow you to make API calls via browser extensions and desktop apps. In this article, we will be using Insomnia as the API client. 

Simplify WooCommerce ETL with Hevo’s No-code Data Pipelines

Hevo Data, a No-code Data Pipeline helps to load data from any data source such as Databases, SaaS applications, Cloud Storage, SDK’s, and Streaming Services and simplifies the ETL process. It supports 100+ data sources including WooCommerce and is a 3-step process by just selecting the data source, providing valid credentials, and choosing the destination. Hevo not only loads the data onto the desired Data Warehouse but also enriches the data and transforms it into an analysis-ready form without having to write a single line of code.

Get Started with Hevo for Free

Its completely automated Data Pipeline offers data to be delivered in real-time without any loss from source to destination. Its fault-tolerant and scalable architecture ensure that the data is handled in a secure, consistent manner with zero data loss and supports different forms of data. The solutions provided are consistent and work with different BI tools as well.

Check out why Hevo is the Best:

  • Secure: Hevo has a fault-tolerant architecture that ensures that the data is handled in a secure, consistent manner with zero data loss.
  • Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
  • Minimal Learning: Hevo, with its simple and interactive UI, is extremely simple for new customers to work on and perform operations.
  • Hevo Is Built To Scale: As the number of sources and the volume of your data grows, Hevo scales horizontally, handling millions of records per minute with very little latency.
  • Incremental Data Load: Hevo allows the transfer of data that has been modified in real-time. This ensures efficient utilization of bandwidth on both ends.
  • Live Support: The Hevo team is available round the clock to extend exceptional support to its customers through chat, email, and support calls.
  • Live Monitoring: Hevo allows you to monitor the data flow and check where your data is at a particular point in time.
Sign up here for a 14-Day Free Trial!

4) Connecting to the API Client

Now that you have the API client, it’s time to make your first API call. Follow the steps given below:

Step 1: Launch the Insomnia app and click “New Request”.

WooCommerce REST APIs - Connecting API Client
Image Source

Step 2: Click “Basic Auth” under the “Basic” dropdown menu.

Step 3: You will be prompted to enter your username and password. The username is the Consumer Key while the password is the Secret Key.

5) Issuing a GET Request

Now that you have configured the API client, you can start to issue API requests. You can issue a GET request to return all the orders to ensure that the API is working. Enter the following request in the GET Request field:

https://yourdomain.com/wp-json/wc/v3/orders

Make sure that you use the correct domain name according to your website. 

The API request will return a JSON String, then Insomnia will parse it. The output should show all the orders available in your store. 

6) Issuing a PUT Request

You can now issue a PUT Request to send a single product to the catalogue. Other than knowing that the API keys are working correctly, the two requests will help you confirm that you have both read and write access to the API. Follow the steps given below:

Step 1: Click the GET dropdown menu and choose the “PUT” option so as to send a PUT request to the server.

Step 2: Open the dropdown menu and choose “JSON”. The write details will be sent in JSON format.

The request should be as follows:

{
  "name": "Product 20",
  "type": "simple",
  "regular_price": "8.99",
  "description": "product description.",
  "short_description": "short product description.",
  "categories": [
    {
      "id": 6
    },
    {
      "id": 8
    }
  ],
  "images": [
    {
      "src": "http://mywebsite.com/img1.jpg"
    },
    {
      "src": "http://mywebsite.com/img2.jpg"
    }
  ]
}

Step 4: Click the “Send” button. The product will be added to the list of items available in the catalogue.

That’s how you use the WooCommerce REST API and carry out few operations.

Conclusion

This blog discussed how to use WooCommerce REST API and provided a brief understanding of WooCommerce APIs.

Extracting complex data from a diverse set of data sources such as WooCommerce, REST APIs, etc. can be a challenging task and this is where Hevo saves the day!

Visit our Website to Explore Hevo

Hevo Data, a No-code Data Pipeline provides you with a consistent and reliable solution to manage data transfer between a variety of sources such as WooCommerce and REST APIs, and a wide variety of Desired Destinations with a few clicks.

Hevo Data with its strong integration with 100+ Data Sources (including 40+ free sources) like WooCommerce and REST API allows you to not only export data from your desired data sources & load it to the destination of your choice, but also transform & enrich your data to make it analysis-ready so that you can focus on your key business needs and perform insightful analysis using BI tools. 

Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand.

Share your experience of understanding WooCommerce REST API in the comment section below!

Nicholas Samuel
Technical Content Writer, Hevo Data

Skilled in freelance writing within the data industry, Nicholas is passionate about unraveling the complexities of data integration and data analysis through informative content for those delving deeper into these subjects. He has written more than 150+ blogs on databases, processes, and tutorials that help data practitioners solve their day-to-day problems.

No-code Data Pipeline for WooCommerce