J
J
Just_Bruh2020-06-07 23:10:28
Python
Just_Bruh, 2020-06-07 23:10:28

How to create a simple product through the woocommerce API (python)?

This is my first time working with the API, so I need help. Much is not required, you just need to create a product with your own: name, price and picture. I read the documentation, but did not fully understand it, it would be nice to see an example of a ready-made code for creating a product.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-06-08
@azerphoenix

Hello!
I worked with WC through Java, but the principle is the same.
1) Get a token in the admin panel for subsequent authorization.
2) Code snippets for work are provided at the office. WC site
https://woocommerce.github.io/woocommerce-rest-api...
There are snippets for Python too.
For example authorization:

from urllib.parse import urlencode

store_url = 'http://example.com'
endpoint = '/wc-auth/v1/authorize'
params = {
    "app_name": "My App Name",
    "scope": "read_write",
    "user_id": 123,
    "return_url": "http://app.com/return-page",
    "callback_url": "https://app.com/callback-endpoint"
}
query_string = urlencode(params)

print("%s%s?%s" % (store_url, endpoint, query_string))

Creating a product - https://woocommerce.github.io/woocommerce-rest-api...
Please note that the image itself must first be uploaded to the site via the WP Media API, and then add a link to the request body when working with WC
https: //developer.wordpress.org/rest-api/reference...
You can also look for ready-made libraries for the convenience of working with the WC API through python.
https://github.com/woocommerce/wc-api-python
Google help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question