How to consume woocommerce products externally via api? wordpress

asdriel

Member
Apr 26, 2019
198
17
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
 

cesar360

New member
Aug 25, 2018
28
14
3
São Paulo, Brazil
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:

 

apaez1

New member
Oct 22, 2020
9
2
3
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?
 

apaez1

New member
Oct 22, 2020
9
2
3
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.
 

MrSam_1

Well-known member
Administrative
Trusted Seller
Dec 1, 2018
23,640
26,991
120
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

apaez1

New member
Oct 22, 2020
9
2
3
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

MrSam_1

Well-known member
Administrative
Trusted Seller
Dec 1, 2018
23,640
26,991
120
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.
 

apaez1

New member
Oct 22, 2020
9
2
3
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.
 

MrSam_1

Well-known member
Administrative
Trusted Seller
Dec 1, 2018
23,640
26,991
120
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.
 

apaez1

New member
Oct 22, 2020
9
2
3
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.
 

Forum statistics

Threads
69,229
Messages
908,458
Members
237,125
Latest member
b4lance10

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu