• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

How to consume woocommerce products externally via api? wordpress

asdriel

Member
Apr 26, 2019
199
18
18
www.bantu-2rsn.com
How to consume woocommerce products externally via api? wordpress
I intend to consume the products for an external application to wordpress, developed in React
 
did you already checked the API DOCS?

You can create,delete,list and update woocommerce products from API to do it you must create your credentials token and then use curl to do operations.

here is an example to create a new product via POST:


curl -X POST https://example.com/wp-json/wc/v3/products \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Premium Quality",
"type": "simple",
"regular_price": "21.99",
"description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",
"short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
"categories": [
{
"id": 9
},
{
"id": 14
}
],
"images": [
{
"src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
},
{
"src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
}
]
}'


as you can see its a JSON formated file, i found this very useful article when a guy build a basic CRUD exactly like you intend to do whit react:

 
Hi there,

I want to be able to create the products in woocommerce by getting the information of the products (title, price, stock, description) from our database wich we use to do some other stuff inside our organization. We have more than 8000 products (simple, not variable) and that is the reason why we would like to create the products using the information that is already in the database. We use Microsoft SQL Server for our database.

We want to sync data, so if something changes on our Microsoft database it updates products on our WordPress one and vice versa. Since our database is connected to an app, that we use to update the stock of products, It would be great if the woocommerce database is updated whenever there is an new item or change of stock in the database.

Yesterday I was able to create a product and retrieve a product using the Woocommerce API (no connection to my DB). Next step I guess would be developing an ETL process so we can get the information of the products from my database, transform it so woocommerce API can understand the data and then uploading that to woocommerce through the API.

Do you now any other way to accomplish this?

There is a problem with this approach: It would not be an automatic process. So, there would not be a continuos syncing.

Is there a way to automate this process?
 
I won't be buying you a beer in this ocassion.

Would you be able to provide more information on this matter? Would you be able to do the job (I know I would have to pay)?

Thanks in advance.
 
Well, my mom taught me to not talk with strangers. IF you wouldn't have missed the introductory section maybe my answer would have been different.
Don't buy a beer for that answer. Tell me this: your MSSQL server is online or local network? It does have external access?
Depending on your answer you'll have to buy me 2 beers for the simplest idea of how to make it work
 
  • Like
Reactions: apaez1
Well, my mom taught me to not talk with strangers. IF you wouldn't have missed the introductory section maybe my answer would have been different.
Don't buy a beer for that answer. Tell me this: your MSSQL server is online or local network? It does have external access?
Depending on your answer you'll have to buy me 2 beers for the simplest idea of how to make it work

I'm sorry for the rudeness that it represents signing up in a community and start asking question without taking a look at the rules, my bad. I apologize for this.

Server is online and we it does have external access.
 
  • Like
Reactions: Mr G
Your apologies accepted. And yet you still have to buy me couple beers for this

Instead of using the api you can directly create the products in the database using a script on your shop server. Not saying that the api won't work. How to make it automated I'll tell you after I get my beers.
 
Your apologies accepted. And yet you still have to buy me couple beers for this

Instead of using the api you can directly create the products in the database using a script on your shop server. Not saying that the api won't work. How to make it automated I'll tell you after I get my beers.

The products are there in the database but after taking a look at the Wocoommerce API and Wordpress databases where the product information is storage, I guess Woocommerce will not understand the information coming from MSSQL. That's the reason why I think I would need to use the API.
 
I already told you there is a solution, even automated one. And would do even more than adding products on your woo shop.
Told you, the idea only will cost you couple beers. If you want the script then we talk privately other prices.
 
I already told you there is a solution, even automated one. And would do even more than adding products on your woo shop.
Told you, the idea only will cost you couple beers. If you want the script then we talk privately other prices.

Thank you very much for your response, I'll be buying you those beers.
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock