How To Use The WooCommerce API

How To Use The WooCommerce API

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 in your eCommerce store. This article explores each of these tasks to enable you to make API requests in interact with your WooCommer store. You can then use these API calls to create your own plugin or connect a PHP based web app to WooCommerce.

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 application and not build a custom API I would highly recommend using something like Zapier or Integromat instead.

Let’s begin!

Step 1: Enable API access in WooCommerce

The first step before you can use the WooCommerce API is to enable it in WordPress Admin. To enable the WooCommerce REST API, login to the backend of your WordPress site, hover over WooCommerce > Settings > Advanced.

Next toggle the Legacy API tab and select Enable the legacy REST API.

Step 2: Add a API keys with Read/Write access

After you have enabled the WooCommerce REST API, you need to create an API key. The key that you generate in this process will authenticate your API requests. An API key ensures that WooCommerce serves only legitimate API requests.

In WordPress Admin, click REST API to add a key. Enter the description, select the user and permissions and click on Generate API Key.


What your name the Description does not matter.

For this tutorial, we recommend to give Read/Write access. 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.


Copy 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 the key into the repository.

Step 3: 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 WooCommerce in your WordPress site through an API client.

For the purposes of this tutorial, you can download Insomnia, the API client that we will use to test GET and PUT requests.

You could also download Postman to make API requests. Both Insomnia and Postman enable you to make API calls through desktop apps or browser extensions.

Step 4: 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

Step 5: 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:

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”. To solve this error, you can check out this post on how to fix common WooCommerce REST API issues.

Step 6: 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:{insert order ID}
For my example, the GET request was the following URL:

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

GET a single order{insert order ID}

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

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

GET a single product{insert product ID}

GET a product variation{insert product ID}/variations/{insert variation ID}

GET all customers

GET a single customer{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:{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:

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:

  • Replace 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


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"

Helpful Tips and Additional Resources

If you have any questions or looking for more examples, let me know in the comments.

I will do my best to help in a timely manner and also add additional examples to this post for future readers.

WooCommerce API

WooCommerce API

See detailed documentation about the WooCommerce API.

Read more

Leave a reply

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted. Your email address will not be published. Required fields are marked*


  1. Wesley Townie April 21, 2019 | 8:08 pm

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

    • Simon Gondeck April 21, 2019 | 9:47 pm

      Wesley – glad you enjoyed it! I added an example at the end of the tutorial on how to update a customer’s shipping address.

  2. Ismail Kimyacioglu July 3, 2019 | 1:24 pm

    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.

    • Simon Gondeck July 3, 2019 | 2:20 pm

      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?

      • Ada July 23, 2020 | 6:43 pm

        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?

        • manos March 5, 2021 | 9:55 am

          Hello, have you found a solution to your problem yet. If not I think I can Help. Send me an email.

      • Angelina Sander August 24, 2020 | 11:14 am

        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.

        • Manos Smar March 5, 2021 | 9:54 am

          Hello, have you found a solution to your problem yet. If not I think I can Help. Send me an email.

  3. Jannath Hussain July 25, 2019 | 1:34 am

    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????

  4. jibs August 19, 2019 | 7:26 pm

    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
    • Simon Gondeck August 19, 2019 | 9:24 pm

      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?

      • jibs August 20, 2019 | 10:13 pm

        Wow, Simon. Thanks. #4 did the trick. You saved me a lot troubleshooting!

    • Data July 3, 2020 | 9:50 pm

      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.

  5. Charles September 26, 2019 | 11:59 pm

    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.

  6. OMAR October 13, 2019 | 1:37 am

    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{id} and the JSON body something like this:


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

  7. Soha Zain October 14, 2019 | 1:24 pm

    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

  8. Pasacal Burckhardt October 18, 2019 | 3:52 am

    Hi Simon

    We are running a GPS/Tracking plattform and now we would like to do the commercial part and the crm with WordPress/Woocommere. We are beginners with Rest-API and need some training.

  9. Muhammad Sarim Iftikhar January 7, 2020 | 6:42 am

    Please send a video how to create a new order using woocommerce api

    • WAN MOHD AFENDI BIN October 13, 2020 | 10:33 am

      Yes. I need it oo

  10. Rushab January 10, 2020 | 4:24 am

    Hello, can you please Explain one POST url? I want to Create User Using REST Api

  11. Gino Van Achte February 2, 2020 | 5:56 am

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

  12. Zak February 17, 2020 | 6:39 am


    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?


    • Leslie April 29, 2021 | 6:54 am

      did you find an answer?

  13. henok May 1, 2020 | 7:24 am

    anyone, please help me to get products by category

  14. Amable Leonc May 7, 2020 | 10:50 pm

    hi ,excelent post. congratulations !

    in my case. when try to fetch information in:


    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 ?

    • Sandipa Mukherjee August 31, 2020 | 7:26 am

      same issue

  15. Jared June 10, 2020 | 5:02 am

    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.

  16. Vít June 12, 2020 | 2:07 am

    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?

  17. Burak August 1, 2020 | 5:25 pm

    Thanks for great post
    how to get checkout custom fields with API?
    Like tax number field we have added?

  18. Anil September 27, 2020 | 4:15 pm

    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.

  19. Mert October 21, 2020 | 1:17 pm

    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.


    • Martin April 26, 2021 | 1:44 am

      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.

  20. Gus October 24, 2020 | 9:57 pm

    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

    • Martin April 26, 2021 | 1:49 am

      check this filter woocommerce_rest_batch_items_limit.

  21. Pablo November 13, 2020 | 3:06 pm

    great post, thanks for sharing. can you provide any tutorial to use the api from .net c#

  22. Rgoyal December 14, 2020 | 9:30 pm

    I am trying to achieve following… is there any solution for this:

  23. Max January 7, 2021 | 7:01 am

    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?

  24. Julio January 29, 2021 | 11:47 am

    I would like to learn how to create a public product query, and be able to insert it into a php page

  25. Aaron February 3, 2021 | 5:46 pm

    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.

  26. Zeedo65 February 4, 2021 | 6:05 pm

    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:
    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 I get a 404 message. So, all my efforts stops at this stage. Can you please help me?

    • Simon Gondeck February 7, 2021 | 9:02 am

      Hey there, did you follow step “Connect to Insomnia with the API keys” in Insomnia?

  27. Cam February 11, 2021 | 9:05 am

    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?


  28. Pritam February 17, 2021 | 4:21 am

    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 🙂

    • Simon Gondeck September 6, 2021 | 10:26 pm

      I would recommend using the WooCommerce Shipment Tracking plugin. Here is more info: view here.

  29. houssem February 24, 2021 | 9:13 am

    there is only get and update how i creat a product using rest api
    please help

  30. Allen March 2, 2021 | 6:57 pm

    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?

    • Simon Gondeck May 26, 2021 | 6:04 pm

      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.

  31. Dayle Senior April 24, 2021 | 4:21 am

    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.

  32. Julio César May 18, 2021 | 8:59 pm

    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.

    • Simon Gondeck May 18, 2021 | 9:03 pm

      Hey Julio, what CRM are you trying to integrate with the WooCommerce API?

      • Julio César May 19, 2021 | 10:21 am

        Hi Simon, thanks for your answer, the CRM is Stel Order I never heard before, but I have a client who works with this few months ago and he needs to use with woocommerce, I will be very grateful any clue you can give me.

        • Simon Gondeck July 19, 2021 | 5:30 pm

          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.

  33. Eddy June 9, 2021 | 8:39 am

    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?

    • Simon Gondeck July 19, 2021 | 5:25 pm

      Hey Eddy! You could use the REST API. I also would recommend looking into using something like CoCart (built for WooCommerce stores that want to have a headless site).

  34. junior August 19, 2021 | 10:03 pm

    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?


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