How To Use The WooCommerce API - TemplateTrip Help

Mega Monsoon Days Sale

Limited-time deal: Up to 70% off Hurry before it ends!
Save Now

Days

Hrs

Min

Sec

Product successfully added to your shopping cart.

How To Use The WooCommerce API

Table of Contents

Requirements for WooCommerce REST API

  • Go to Dashboard → Settings → Permalinks.
  • Select the Post Name option, and click the Save button.

Getting Started With WooCommerce API
WooCommerce is an open-source e-commerce platform built on WordPress. The WooCommerce API allows developers to interact with the WooCommerce store data programmatically.

1. Install and set up WooCommerce: Before you can start using the WooCommerce API, you need to have WooCommerce installed and set up on your website.

2. Generate API Keys: To authenticate requests to the API, you need to generate API keys. You can do this by navigating to the WooCommerce settings and clicking the Advanced tab, followed by REST API. From here, you can generate keys for each user needing API access.

3. Choose an API endpoint: WooCommerce provides several endpoints for accessing different data types, such as orders, products, customers, and more. Choose the endpoint that corresponds to the data you want to access.

4. Make an API request: To make a request to the API, you can use any programming language that can send HTTP requests. You must include your API key in the request headers to authenticate the request.

5. Process the API response: The API will return data in a JSON format. You can parse this data and use it in your application as needed.

Creating API Keys in WooCommerce

  • Log in to your WordPress dashboard and navigate to WooCommerce → Settings.
  • Click on the Advanced tab and then click on the REST API tab.
  • Click the Add Key/Create an API Key button to create a new API key.
  • Enter a description for the API key in the Description field.
  • Select the user from the User dropdown list to associate with the API key. You may need to create a new user if you don’t see the user you want to use.
  • Choose the permissions you want to grant the API key from the Permissions dropdown list. You can choose between Read/Write, Read-only, and Write-only permissions.
  • Click the Generate API Key button to generate the API key.
  • Make sure to copy the Consumer Key and Consumer Secret values and save them somewhere secure, as you won’t be able to view them again.

Enable the Legacy Rest API
The first step is enabling the legacy REST API; to do this, you must follow the below steps.

  • Go to WooCommerce → Settings → Advance.
  • Click on the Legacy API option.
  • Check mark the Enable the legacy REST API option.
  • Click on the Save Changes button to implement the changes.

Test WooCommerce REST API on Postman
Postman is an API platform for building and using APIs. First, you need to sign up to test the API on Postman.
The requested URL we’ll test is wp-json/wc/v3/orders. For my website, the full URL looks something like this:

https://wordpress-1013933-3583354.cloudwaysapps.com//wp-json/wc/v3/orders

Once you successfully log in to Postman, follow the steps below to perform the REST API testing.

  • First, open the WooCommerce REST API document on the new tab.
  • Second, open the Postman on the other tab on your browser.
  • Go to your WooCommerce REST API document and search for the Orders.
  • Copy the code from the right side panel.
  • Now, redirect to the Postman tab.
  • Click on the Collections.
  • Click on the Import.
  • Paste the order code that you copied from the WooCommerce REST API document.
  • Select the Request Type as GET.
  • Edit the Request URL to use your own site URL.
  • Now do the settings on the authorization tab.
  • For Authorization, choose Basic Auth.
  • Enter your Consumer Key and Consumer Secret Key from WooCommerce into the Username and Password fields.
  • If you have set up your WooCommerce store properly and have enabled the REST API and generated API keys, you should see a JSON response that contains a list of products in your store. The response should look something like this:
  • Here is the Postman platform guide with the marking that can help you understand where you need to make changes.