How To Use The WooCommerce API (without knowing how to code!)

WordPress is the most popular content management system. Site owners have utilized WordPress for a variety of uses through plugins. WooCommerce turns a WordPress site into an eCommerce store. In addition to the basic functionality that a WooCommerce site provides, one can utilize the WooCommerce API to extend the features and functionality of the eCommerce store. In this article, you will learn how to get started with the WooCommerce API to interact with your WooCommerce store.

WooCommerce API is an extension of WordPress REST API. The WordPress REST API in PHP allows an application to interact with WordPress’s functionality. One can use the WooCommerce API to read, create, update, and delete data. This article explores each of these tasks to enable you to make API requests that interact with your WooCommerce store. You can then use these API calls to create your own plugin, connect a 3rd party web app, and more.

When you make a REST API call, WooCommerce and WordPress connect with the PHP and SQL backend to process your request and generate the output.

Later in the tutorial, we include plenty of examples of GET and PUT requests that you can copy or modify on your own to extend the functionality on your WooCommerce store by creating a plugin using PHP.

If you just are trying to integrate WooCommerce with another web app and not build a custom API I would highly recommend using something like Zapier or Make instead. For example, you want to add a customer to a mailing list or update an order with custom metadata.

Let’s begin!

Create API Keys in WooCommerce

Before we can use the WooCommerce API, we need to create API keys. The keys that you generate will authenticate your API requests. An API key ensures that WooCommerce serves only legitimate API requests.

In the WordPress backend go to WooCommerce > Settings > Advanced.

Next toggle the REST API tab.

Create a new API key.

Enter the description and set your permissions to Read/Write and click on Generate API Key.

woocommerce-api-key-details
What your name the Description does not matter.

For this tutorial, I recommend Read/Write permissions. This will allow you to create, read, update and delete WooCommerce data through the API.

Once finished, click Generate API key. Notice the two alphanumeric strings – they are your consumer key and consumer secret.

woocommerce-api-consumer-keys-secret

Copy/paste your Consumer key and Consumer secret to a safe place. We will need them to connect to the WooCommerce REST API. These keys are processed by the PHP backend every time a request is made. If you are using version control to manage your code with GitHub, do not commit this key into the repository. You always can create a new API key if need be.

Here is a short video about how to get your API keys in WooCommerce.

Download an API client like Insomnia

Though you have enabled the WooCommerce API and created an API key to use, you will need an API client to make requests and view responses. You will use your API keys to connect to WooCommerce through an API client.

For the purposes of this tutorial, you can download Insomnia (free), the API client that we will use to test GET and PUT requests. You could also use Postman (free) to make API requests. Both Insomnia and Postman enable you to make API calls through desktop apps or browser extensions.

Use your API keys to connect to Insomnia

After downloading Insomnia, let us make our first API call. Open the Insomnia application and click New Request.

Under the Basic tab dropdown, click on Basic Auth :

Next, enter your Consumer key and Consumer secret. Set the fields as shown below.

  • username = consumer_key
  • password = consumer_secret

Make your first GET request

After configuring the Insomnia app, you are now ready to make API requests. You can start with a GET request to get all orders just to make sure the API keys are working correctly.

In the GET request, enter a GET request to view all orders:

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

The response of this API request is a JSON strong and Insomnia parses it for you. You should see all orders in your store in the output.

If everything does not work out well, you may get the 401 error with the message – “Sorry, you are not allowed to edit this resource”. Double check that you are using the correct API keys. Also, make sure your url is typed in correctly! If you are still having issues, check out this post on how to fix common WooCommerce REST API issues.

Make your first PUT request

Once you have made a successful GET request, you can now explore further. Similar to the GET request, you could do a PUT request to update a single order on the server. In addition to the API keys working correctly, this request ensures that you have both Read and Write access.

To update an order, you can first make a GET request to view the details of a single order:

https://yourdomain.com/wp-json/wc/v3/orders/{insert order ID}

For my example, the GET request was the following URL:

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

Next, click the GET dropdown and choose PUT option to make a write request to the server.

Next, go to the dropdown to choose JSON. JSON is a format in which you send the write details through the request.

Use this example to update the order status from “processing” to “completed”.

{
  "status": "completed"
}

Helpful tips

  • The Consumer key should start with “ck_”
  • The Consumer secret should start with “cs_”.
  • If necessary, you always can regenerate your API keys again in WooCommerce.

WooCommerce GET request examples

Now that you have successfully made read and write requests to the server through the API keys, let us explore examples of more GET requests.

If you are having retrieving any of these examples, make sure you scroll up to how to do GET requests.

GET all orders

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

GET a single order

https://yourcompany.com/wp-json/wc/v3/orders/{insert order ID}

For example, the order ID is 82513, so I would use the following URL path to retrieve this order:

https://yourcompany.com/wp-json/wc/v3/orders/82513/

Pro tip: Find the order ID by going to clicking on the order and looking at number after “post=”. See the screenshot below for reference.

GET all products

https://yourcompany.com/wp-json/wc/v3/products/

GET a single product

https://yourcompany.com/wp-json/wc/v3/products/{insert product ID}

GET a product variation

https://yourcompany.com/wp-json/wc/v3/products/{insert product ID}/variations/{insert variation ID}

GET all customers

https://yourcompany.com/wp-json/wc/v3/customers/

GET a single customer

https://yourcompany.com/wp-json/wc/v3/customers/{insert customer ID}

WooCommerce PUT request examples

Next, let us explore some examples of write requests.

Update product price

To update the “regular_price”, here is a example PUT request:

https://yourcompany.com/wp-json/wc/v3/products/{insert product ID}

Click Body > JSON and enter this query

{
"regular_price": "81"
}

Update product price and stock quantity

To update the “regular_price” and the “stock_quantity”, here is a example PUT request:

{
 "regular_price": "81”,
 “stock_quantity": 45
}

Update product meta data

To update product meta data, here is a example PUT request:

{
  "meta_data": [
    {
      "key": "_net_price",
      "value": "40"
    }
  ]
}

Pass the “key” as name of database field, and value as value.

Update price of product variant

example url: https://yourdomain.com/wp-json/wc/v3/products/833/variations/854

To update a product or product variant’s “price” or “regular_price”, here is a example PUT request:

Click Body > JSON and enter this query

{
 "regular_price": "81"
}

Pass the “key” as name of database field, and “value” as value.

Update customer’s first and last name

example url: https://yourdomain.com/wp-json/wc/v3/customers/3144/

  • Replace https://yourdomain.com with your domain
  • Replace 3144 with a specific customer ID in your store.
  • Find customer ID by clicking “edit” on the specific customer in WooCommerce and looking for the value after user_id=XXXX. In the example below, the customer ID is 3144
woocommerce-api-customer-id

To update the “first_name” and “last_name”, here is a example PUT request:

Click Body > JSON and enter this query

{
  "first_name": "John",
  "last_name": "Doe"
}

Update customer’s shipping address

To update a customer’s shipping address, here is a example PUT request:

Click Body > JSON and enter this query

{
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "Storm Creek",
    "address_1": "110 Demo Drive",
    "address_2": "Suite 110",
    "city": "Minneapolis",
    "state": "MN",
    "postcode": "94203",
    "country": "US"
  }
}

Update line item meta data in a Order

Use this example to update line item meta in a specific Order. I would recommend doing a GET request and viewing the order meta data.

{
	"line_items": [
		{
			"id": 6316,
			"meta_data": [
				 {
          "id": 62589,
          "key": "_zoho_books_item_id",
          "value": "366243000000151613",
          "display_key": "_zoho_books_item_id",
          "display_value": "366243000000151613"
				 }
			 ]
		 }
	 ]
}

FAQ

Do you know how I can update a customers shipping address with WooCommerce API?

To update a customer’s shipping address, you need to have a PUT request.

Here is a example of an PUT request: Click “Body” > “JSON” and enter this query

{
	"shipping": {
	"first_name": "John",
	"last_name": "Doe",
	"company": "Storm Creek",
	"address_1": "110 Demo Drive",
	"address_2": "Suite 110",
	"city": "Minneapolis",
	"state": "MN",
	"postcode": "94203",
	"country": "US"
	}
}

How to connect WooCommerce API with Insomnia?

1. After downloading Insomnia, open the application and click “New Request”.

2. Under the “Basic” tab dropdown, click on “Basic Auth” and enter the following credentials:

3. Next, enter your consumer_key and consumer_secret for the API keys you generated on your WooCommerce dashboard.

  • username = consumer_key
  • password = consumer_secret

Helpful Tips and Additional Resources

Simon Gondeck

I’m a big fan of WordPress + WooCommerce (especially WooCommerce Subscriptions). Check out my YouTube channel.

72 thoughts on “How To Use The WooCommerce API (without knowing how to code!)”

  1. Hi Simon, thanks for all. Do you know how to configure Insomnia to connect to a website protected with a Ngnix Basic Auth? You should have two “basic auth” settings, one for the Nginx and one for the WooCommerce API. I tried many solutions but anything works 🙁

    Reply
  2. Thanks for the descriptive guide. For me, when I create a product, the description or the price does not appear. I was looking at exactly how the data should be sent….but I couldn’t figure out why when creating a product its name is product-(some number) and not what I chose? I use Postman, Windows 10.
    Is there a place where I can actually track if all the operations are successful -CREAT, READ, UPDATE, DELETE – free?

    Reply
  3. After successfully testing the GET command in Insomnia, I am only seeing 10 Rows of Woo Commerce orders. Does Insomnia limit the Preview to 10 records via: /wp-json/wc/v3/orders?

    Reply
    • Pagination
      Requests that return multiple items will be paginated to 10 items by default. This default can be changed by the site administrator by changing the posts_per_page option. Alternatively the items per page can be specified with the ?per_page parameter:

      GET /orders?per_page=15

      You can specify further pages with the ?page parameter:

      GET /orders?page=2

      Reply
  4. Hi, Simon!
    I am currently working on implementing the connection between woocommerce and my client’s ERP. I have some documentation from the ERP but don’t really know where to start with all this. I’ve designed the whole website, but unfortunately, the ERP doesn t have a plugin, they just gave some api methods and I just have to deal with them. I haven’t done anything like this before. Is there any way I can contact you for some one to one consulations on this matter. Paid, of course. Thank you!

    Reply
  5. hey, thanks for the good instructions. I ask if you have any instructions for the following: I have a data grid where the products are listed. how do I get product details displayed when I click on a product in the data grid? I get the code done that takes me to the front end product page but how do I get the product information for it through the woocommerce rest api?
    I am grateful for the information.

    Reply
  6. No Brasil há várias faixas e critérios de aplicação de impostos e tributos, dependendo do tipo do produto da região, da localização do comprador e também da origem do Seller. Seria possível apresentar os valores exatos desses impostos antes do Checkout?

    Reply
  7. Hi, thanks for your explanations, how can I filter all orders that contain product id X or customers who haven’t purchased for more than 90 days?

    Reply
  8. Hey Simon, Great Article. Hope you can help with the following request. I would like to integrate shipping in woocommerce via an api from a shipping company (who doesn’t have an app). The api would send requests to the shipping company’s website where they have cost calculations. Thanks Much

    Reply
  9. Hi I have some issues with the get all products i dont get them all we have 5000 product, and i dont get them all. I use Insomnia And one more thing is it possible to filter the get, so i just get the Product id and regular and sale price 🙂 I use the free version. best regards Morten

    Reply
  10. Hi, I want to create a selection of product and add to cart via REST API is possibile? Or I need to create a virtual cart independent and complete the order also via rest api?

    Reply
  11. Hi Simon, may be you can give me a hand with this, I need to connet a CRM with woocommerce but this CRM doesn’t have any support or plugin only has an api, how can do this with innsonia, any clue? I will apreciated your help.

    Reply
        • Hey Julio, I would look at using Integromat to automate this. It would probably be a lot easier than building your own custom API. Integromat would be the middle man between WooCommerce and Stel Order. Integromat does have integration with WooCommerce but no integration with Stel Order. However, Integromat allows you to do custom HTTP requests. For example, you could setup a scenario on Integromat when a new order is created and then send that data using a custom HTTP request to Stel Order.

          Reply
  12. Hi Simon,
    My problem is a little different to the rest of the comments. I am wondering how I should use the WooCommerce REST API in regards to a Multisite Network?

    Rather than connecting 10+ Sub-sites with separate API keys to our CRM, surely there is a way to connect the Multisite as a whole? I have been googling for days but not found an answer.

    Reply
  13. Hello, Great tutorial. however, I have been looking around regarding woocommerce rest api and every tutorial seems to use the woocommerce api ONLY to manage their store. But what i want to do is build an app version of my store such that customers can login and get all their specific information while NOT having access to back end information like other customer information.
    Can the api be used in this way or is it only for managing your store?

    Reply
    • Yes the WooCommerce API could be used this way however some things about the WooCommerce API is limited. However, you can always use the WordPress REST API with WooCommerce as well. CoCart is another option if you wanted to build a headless WordPress/WooCommerce site with Frontity, Next js, or Gatsby.

      Reply
  14. Hello , thank you for the great tutorial first . I have my shipping partner who has provided me with the api documentation . There is no prebuilt plugin available for the partner’s shipping integration . SO how can i integrate it in my wordpress site ? How can I track the orders through the website and how can customers automatically get their tracking id in their account.
    Thank you for the help in advance 🙂

    Reply
  15. Hello Simon,
    I followed the tutorial, everything works for me on Insomnia but I do not understand how to display the products of the stream on my shop WooCommerce?

    I try to import products from another WooCommerce site onto mine via their API.

    Should we export the Insomnia code?
    Do I need to import something into my database?
    In what directory, file?

    THX

    Reply
  16. Hello
    Thanks for this interesting post. I am a beginner with APIs and I have a question if you please help me.

    I can not understand
    It is a long time I want to figure out this address:
    https://yourdomain.com/wp-json/wc/v3/orders
    Where shoud I get this address for my own woocommerce website? I know that I should change it to my personal domain, but, I do not understand where did I specified “wp-json/wc/v3/orders”. When I add the address “wp-json/wc/v3/orders” after https://mydomain.com/ I get a 404 message. So, all my efforts stops at this stage. Can you please help me?

    Reply
  17. Why are we enabling the legacy API as part of this tutorial? Just wondering because I don’t have it enabled and I’m having a connection error that I really cannot find the solution to.
    Thanks

    Reply
  18. How could I list all completed orders containing a specific phone number? I don’t see phone number as a possible parameter in the official doc for endpoint wp-json/wc/v3/orders
    Any workaorund?
    Thanks!

    Reply
  19. Hi! How can I get all orders in only one get, I know woocommerce has a limit at 100 records per page. I dont want to do pagination. Thanks a lot

    Reply
  20. Hello Simon. I have 2 sites.
    On the 1st site, all transactions will be made except payment. Pressing the payment button will be directed to the 2nd site (all order information, selected payment method, membership information, shipping information, etc.)
    He will make the payment on site 2 and then be redirected to the 1st site.

    Is this possible? Where should I start, how can I do it? Can you help.

    Thanks.

    Reply
    • If its wp multisite will be easyer. If not you have to do more checks then just making the order. For example is it a new customer or not. Do you keep stock quantiy on both websites etc. I think you should build 2 primary routes of logged in customers and guests if you are allowing guests to place orders. I personaly dont get the idea of redirecting users. Looks phishy to me.

      Reply
    • Hola Simon, thank you for sharing invaluable information. I need to synchronize woocommerce with a crm which provided only the sql database. How can I do this synchronization so that the data is updated both in ecommerce and in the physical shop that is managed by this CRM? Thank you for any guidance.

      Reply
  21. Hi Simon,

    Thank you for all the great tips here. Wondering what the GET URL would be for getting order status by searching by a customer’s email address. Thanks in advance for any help or guidance.

    Reply
  22. Hello,
    I am getting 401 woocomerce_rest_cannot_view again and again in inomnia. I don’t found solution in attached link. Any idea how to fix this error?

    Reply
  23. Hello Simon. Thanks for such a useful ‘how-to’. Really thorough and pedagogical! Great! One point though – it say at the top that it’s a ‘6 minute read’! I’ve been working my way through this page for about 2 hours and I’m still trying things out. I think I’ll be back and forth to it for weeks if not forever. It’s a fantastic resource.Thanks again.

    Reply
  24. hi ,excelent post. congratulations !

    in my case. when try to fetch information in:

    https://MYSITE.com/wp-json/wc/v3/products/

    OR

    https://MYSITE.com/wp-json/wc/v3/products?consumer_key=ck_01234567890&consumer_secret=cs_01234567890

    i get :

    { 
    "code": "woocommerce_rest_cannot_view",
     "message": "Sorry, you can not list the resources.", 
    "data": { "status": 401 }
     }

    server problem ? REST API permission ?

    woccommerce issue?

    you can help me please ?

    Reply
  25. Hi,

    Does insomnia help with connecting external apis into woocommerce? I need to do this in order to manage stock automatically.

    If, yes how can I do that?

    Thanks

    Reply
  26. Hi Simon, Can you help me out? I want to update products and price from wholesale site plus my percentage included and then redirect orders to Wholesale site. We are beginners with Rest-API and need some training.

    Reply
  27. Amazingly Great job. These two points are well covered; “Add a API keys with Read/Write access” and “Use your API keys to connect to Insomnia”. Thanks for sharing this topic of “How To Use The WooCommerce API Without Knowing How to Code”. The best part is the article has all the practical detailing! Keep sharing

    Reply
  28. Hello Simon! thanks so much for the great tutorial. I have one question… how can i do for update multiples products in one request. For example i have more than 4000 products, i was using PUT with this endpoint https://www.bachmusic.center/wp-json/wc/v3/products/{id} and the JSON body something like this:

    {
    "sku":"{sku}",
    "name":"{name}",
    "price":"{regular_price}"
    }

    but doesn’t work, i really appreciate your help.
    Thank you so so much!!

    Reply
  29. Hi Simon,
    Thanks for a good tutorial! I need to make use of the API for payment processing by another party. They have a set of variables that need to pass into the API (see below xml request) based on an order number generated earlier by a woocommerce user. I’m trying find a way to edit the endpoint json/wc/v3/orders so that the incoming request can get amount payable for the existing “on-hold” order, add a transaction id (and other variables), then allow the status of the order to be changed to “completed” with another request, confirming the amount paid. I have been able to do basic GET and POST actions with POSTMAN using Basic Auth to the mentioned endpoint. It’s just the editing of that endpoint where I need direction please.

    Reply
  30. Hi Simon, helpful post. Thanks. Using Insomnia if I send the key & secret in the URL as query string parameters I am able to get it work, but as you have it described (buy using Basic Auth) I get the below response. Any ideas?

    {
      "code": "woocommerce_rest_cannot_edit",
      "message": "Sorry, you are not allowed to edit this resource.",
      "data": {
        "status": 401
      }
    }
    Reply
    • Hi Jibs, WooCommerce mentions that occasionally some servers may not parse the Authorization header correctly. This could be due to using WP Super Cache or W3 Total Cache. Robot Ninja wrote a great post that goes over common WooCommerce REST API issues and how to fix them. Look at Issue #1 (caching plugins removing headers) and Issue #4 at this link: How to Fix Common WooCommerce REST API Issues

      Also, when you generated your API keys, are you are administrator on the site? You could also try regenerating your API keys and ensuring you have both Read/Write access but assume you have already done so.

      Are all requests returning this error? For example, are you able to do GET requests but not any PUT or POST requests?

      Reply
    • I took a lot of time – the whole night – trying to fix this “401: Sorry, you are not allowed to edit this resource.” The link shared by Simon is great although it did not work as stated for me. In my case, running my own VPS server, what worked for me was going to WHM then under Service Configuration clicking Apache Configuration. In the “Include Editor:” in the “Pre Main Include”, I selected All Versions and pasted this from Simon’s link there:

      SetEnvIf Authorization “(.*)” HTTP_AUTHORIZATION=$1

      On update it will ask to restart Apache. Restart and test your API – it should work. If you receive a 500 Internal Error, simply deactivate and reactivate woo-commerce plugin in the plugins section of WordPress.

      Hope this helps someone and saves them hours of frustrations.

      Reply
  31. Hi Simon,

    Just like magento api’s.. do we have a flow of rest api’s from login to placing order and logout in wordpress????

    Reply
  32. Hi Simon,

    Thanks for the tutorial. I run an online shop and would like to import bulk products from a vendor company. I asked them to provide an XML file to me so that I can easily upload via converting the XML file to a CSV with Woocommerce schema.

    However, they sent me some information with Rest API. I have been googling to understand the concept but no success, yet.

    As explained on the web, I have activated legacy API and generated ck and cs. However, I still don’t understand where I should write the vendor’s ck and cs.

    Could you please help me ?

    Thanks in advance.

    Reply
    • Hi Ismail, can you explain in more detail what information the vendor company sent to you? For example, did your vendor company send you their consumer_key and consumer_secret? If so, the reason they would provide their keys so you could connect with the REST API on their store. In addition, have you downloaded an API client such as Insomnia or Postman to connect to the REST API?

      Reply
      • Hi Simon, I have a similar problem with Ismail. i downloaded Insomnia. inserted the link provided by the wholesaler, cs & ck generated by my REST API. Got a 200 OK. Now I am stuck at how to transfer the data generated to my website.
        Can you kindly help me out?

        Reply
      • Hi Simon,
        I am in the same situation as Ismail. I need to import products onto my site from a vendor who has provided me with a single API Key. I already downloaded Insomnia and connected my site with the ck & cs and tested both the GET & PUT. All is working. My questions is where do I input the vendor API key that they provided me with or how would I go about setting up the file to transfer the info from their site onto mine using their API key? Thank you for your help.

        Reply
  33. Hey thanks Simon for all the help. Do you know how I would be able to update a customers shipping address with api?

    Reply

Leave a Comment