How To Use The WooCommerce API Without Knowing How to Code

Learn how to get started using the WooCommerce API.
Use the WooCommerce API to add, update, and delete orders, products, customers in your online store.
Later in the tutorial, I include plenty of examples of GET and PUT requests that you can copy or modify on your own for your own use.
Let’s begin!
Steps to start using the WooCommerce API
Additional Resources
Step 1: Enable API access in WooCommerce
To enable the WooCommerce API, login to the backend of your WordPress site, hover over WooCommerce > Settings > Advanced.
Next toggle the “Legacy API” tab > enable > Save Changes.
Step 2: Add a API keys with Read/Write access
Next, click on the “REST API” tab > add a key with your details.
For this tutorial, I recommend to give “Read/Write” access to test GET and PUT requests.
Once finished, click the Generate API key button to view your consumer_key and consumer_secret.
After generating your API keys, keep these keys in a safe place as we will be using them to connect to Insomnia, our API client.
Step 3: Download Insomnia or other API client
Now is the time to use our API keys to connect to our WooCommerce site with an API client.
Download Insomnia, the API client we will use to test GET and PUT requests.
You could also download Postman.
Step 4: Use your API keys to connect to Insomnia
After downloading Insomnia, open the application and click “New Request”.
Under the “Basic” tab dropdown, click on “Basic Auth” and enter following credentials:
Next, enter your consumer_key and consumer_secret for the API keys you generated on your WooCommerce dashboard.
- username = consumer_key
- password = consumer_secret
Step 5: Make your first GET request
To start, I always do a GET request to get all orders just to make sure my 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
You should see all orders in your store.
Are you getting the 401 error “Sorry, you are not allowed to edit this resource” error? Check out this post: How to fix common WooCommerce REST API issues.
WooCommerce Zapier
Automate your WooCommerce store by connecting it to more than 2,000 cloud apps using Zapier.
Step 6: Make your first PUT request
Similar to the GET request, I always do a PUT to update a single order to make sure my API keys are working correctly and I have both Read and Write access.
To update an order, type in a GET request to view 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
Next, go to the dropdown to choose “JSON”.
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.
WooCommerce GET request examples
- View all orders
- View a single order
- View all products
- View a single product
- View a product variant
- View all customers
- View a single customer
If you are having retrieving any of these examples, make sure you scroll up to how to do GET requests.
GET request to view all orders
https://yourcompany.com/wp-json/wc/v3/orders/
GET request to view 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 request to view all products
https://yourcompany.com/wp-json/wc/v3/products/
GET request to view a single product
https://yourcompany.com/wp-json/wc/v3/products/{insert product ID}
GET request to view a single product variation
https://yourcompany.com/wp-json/wc/v3/products/{insert product ID}/variations/{insert variation ID}
GET request to view all customers
https://yourcompany.com/wp-json/wc/v3/customers/
GET request to view a single customer
https://yourcompany.com/wp-json/wc/v3/customers/{insert customer ID}
WooCommerce PUT request examples
- Update product price
- Update product price and stock quantity
- Update product meta data
- Update price of product variant
- Update customer’s first and last name
- Update customer’s shipping address
PUT request to update price of a simple product
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"
}
PUT request to update 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
}
PUT request to 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.
PUT request to 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.
PUT request to update customer’s 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
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"
}
PUT request to 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"
}
}
Helpful Tips and Additional Resources
- How to Fix Common WooCommerce REST API Issues
- Technical Docs: WooCommerce REST API
- How to Connect Your PHP Based Web App to the WooCommerce Rest API
- Video: How to do a GET request to view all orders
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.
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
Comments
Hey thanks Simon for all the help. Do you know how I would be able to update a customers shipping address with api?
Wesley – glad you enjoyed it! I added an example at the end of the tutorial on how to update a customer’s shipping address.
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.
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?
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?
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.
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????
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?
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?
Wow, Simon. Thanks. #4 did the trick. You saved me a lot troubleshooting!
Yes for sure glad I was able to help!
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.
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.
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:
but doesn’t work, i really appreciate your help.
Thank you so so much!!
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
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.
Please send a video how to create a new order using woocommerce api
Yes. I need it oo
Hello, can you please Explain one POST url? I want to Create User Using REST Api
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.
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
anyone, please help me to get products by category
hi ,excelent post. congratulations !
in my case. when try to fetch information in:
OR
i get :
server problem ? REST API permission ?
woccommerce issue?
you can help me please ?
same issue
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.
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?
Thanks for great post
how to get checkout custom fields with API?
Like tax number field we have added?
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.
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.
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
great post, thanks for sharing. can you provide any tutorial to use the api from .net c#
I am trying to achieve following… is there any solution for this:
https://stackoverflow.com/questions/65285177/process-woocommerce-api-using-php-curl