hi i use these documentation to work with python in woocommerece restapi to create product
there is 2 problem with results and i search all stackoverflow and stackexchange but yet can’t solve it
first problem is I can’t assign a category to my product according to documentation no matter how many times i try it doesn’t work
<code>from woocommerce import API
woocommerceApi = API(url="http://starcase.ir",
consumer_key="ck_2df612f9f2a9aabada2c687206525c67774e0ab9",
consumer_secret="cs_3d060e35e8598e0632f3437e88b089f6458e6998", timeout=200000)
data = {"name": name, 'type': 'variable', "categories": [{"id": 479}, {"id": 496}], "images": images_links}
product = woocommerceApi.post("products", data).json()
<code>from woocommerce import API
woocommerceApi = API(url="http://starcase.ir",
consumer_key="ck_2df612f9f2a9aabada2c687206525c67774e0ab9",
consumer_secret="cs_3d060e35e8598e0632f3437e88b089f6458e6998", timeout=200000)
data = {"name": name, 'type': 'variable', "categories": [{"id": 479}, {"id": 496}], "images": images_links}
product = woocommerceApi.post("products", data).json()
</code>
from woocommerce import API
woocommerceApi = API(url="http://starcase.ir",
consumer_key="ck_2df612f9f2a9aabada2c687206525c67774e0ab9",
consumer_secret="cs_3d060e35e8598e0632f3437e88b089f6458e6998", timeout=200000)
data = {"name": name, 'type': 'variable', "categories": [{"id": 479}, {"id": 496}], "images": images_links}
product = woocommerceApi.post("products", data).json()
it goes to uncategorized
<code>{'id': 22530, 'name': 'قاب Piggy سیلیکونی برجسته', 'slug': '%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87', 'permalink': 'http://starcase.ir/product/%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87/', 'date_created': '2024-04-24T19:22:43', 'date_created_gmt': '2024-04-24T14:52:43', 'date_modified': '2024-04-24T19:22:45', 'date_modified_gmt': '2024-04-24T14:52:45', 'type': 'variable', 'status': 'publish', 'featured': False, 'catalog_visibility': 'visible', 'description': '', 'short_description': '', 'sku': '', 'price': '', 'regular_price': '', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'purchasable': False, 'total_sales': 0, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'external_url': '', 'button_text': '', 'tax_status': 'taxable', 'tax_class': '', 'manage_stock': False, 'stock_quantity': None, 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'low_stock_amount': None, 'sold_individually': False, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_required': True, 'shipping_taxable': True, 'shipping_class': '', 'shipping_class_id': 0, 'reviews_allowed': True, 'average_rating': '0', 'rating_count': 0, 'upsell_ids': [], 'cross_sell_ids': [], 'parent_id': 0, 'purchase_note': '', 'categories': [{'id': 15, 'name': 'دسته بندی نشده', 'slug': 'uncategorized'}], 'tags': [], 'images': [{'id': 22529, 'date_created': '2024-04-24T23:52:42', 'date_created_gmt': '2024-04-24T14:52:42', 'date_modified': '2024-04-24T23:52:43', 'date_modified_gmt': '2024-04-24T14:52:43', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/1dc52f-10.jpeg', 'name': '1dc52f-10.jpeg', 'alt': ''}, {'id': 22531, 'date_created': '2024-04-24T23:52:43', 'date_created_gmt': '2024-04-24T14:52:43', 'date_modified': '2024-04-24T23:52:43', 'date_modified_gmt': '2024-04-24T14:52:43', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/e7220b-10.jpeg', 'name': 'e7220b-10.jpeg', 'alt': ''}, {'id': 22532, 'date_created': '2024-04-24T23:52:44', 'date_created_gmt': '2024-04-24T14:52:44', 'date_modified': '2024-04-24T23:52:44', 'date_modified_gmt': '2024-04-24T14:52:44', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/549b69-10.jpeg', 'name': '549b69-10.jpeg', 'alt': ''}], 'attributes': [], 'default_attributes': [], 'variations': [], 'grouped_products': [], 'menu_order': 0, 'price_html': '', 'related_ids': [21512, 20144], 'meta_data': [], 'stock_status': 'outofstock', 'has_options': True, 'post_password': '', 'permalink_template': 'http://starcase.ir/product/%pagename%/', 'generated_slug': 'قاب-piggy-سیلیکونی-برجسته', '_links': {'self': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530'}], 'collection': [{'href': 'http://starcase.ir/wp-json/wc/v3/products'}]}}
<code>{'id': 22530, 'name': 'قاب Piggy سیلیکونی برجسته', 'slug': '%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87', 'permalink': 'http://starcase.ir/product/%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87/', 'date_created': '2024-04-24T19:22:43', 'date_created_gmt': '2024-04-24T14:52:43', 'date_modified': '2024-04-24T19:22:45', 'date_modified_gmt': '2024-04-24T14:52:45', 'type': 'variable', 'status': 'publish', 'featured': False, 'catalog_visibility': 'visible', 'description': '', 'short_description': '', 'sku': '', 'price': '', 'regular_price': '', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'purchasable': False, 'total_sales': 0, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'external_url': '', 'button_text': '', 'tax_status': 'taxable', 'tax_class': '', 'manage_stock': False, 'stock_quantity': None, 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'low_stock_amount': None, 'sold_individually': False, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_required': True, 'shipping_taxable': True, 'shipping_class': '', 'shipping_class_id': 0, 'reviews_allowed': True, 'average_rating': '0', 'rating_count': 0, 'upsell_ids': [], 'cross_sell_ids': [], 'parent_id': 0, 'purchase_note': '', 'categories': [{'id': 15, 'name': 'دسته بندی نشده', 'slug': 'uncategorized'}], 'tags': [], 'images': [{'id': 22529, 'date_created': '2024-04-24T23:52:42', 'date_created_gmt': '2024-04-24T14:52:42', 'date_modified': '2024-04-24T23:52:43', 'date_modified_gmt': '2024-04-24T14:52:43', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/1dc52f-10.jpeg', 'name': '1dc52f-10.jpeg', 'alt': ''}, {'id': 22531, 'date_created': '2024-04-24T23:52:43', 'date_created_gmt': '2024-04-24T14:52:43', 'date_modified': '2024-04-24T23:52:43', 'date_modified_gmt': '2024-04-24T14:52:43', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/e7220b-10.jpeg', 'name': 'e7220b-10.jpeg', 'alt': ''}, {'id': 22532, 'date_created': '2024-04-24T23:52:44', 'date_created_gmt': '2024-04-24T14:52:44', 'date_modified': '2024-04-24T23:52:44', 'date_modified_gmt': '2024-04-24T14:52:44', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/549b69-10.jpeg', 'name': '549b69-10.jpeg', 'alt': ''}], 'attributes': [], 'default_attributes': [], 'variations': [], 'grouped_products': [], 'menu_order': 0, 'price_html': '', 'related_ids': [21512, 20144], 'meta_data': [], 'stock_status': 'outofstock', 'has_options': True, 'post_password': '', 'permalink_template': 'http://starcase.ir/product/%pagename%/', 'generated_slug': 'قاب-piggy-سیلیکونی-برجسته', '_links': {'self': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530'}], 'collection': [{'href': 'http://starcase.ir/wp-json/wc/v3/products'}]}}
</code>
{'id': 22530, 'name': 'قاب Piggy سیلیکونی برجسته', 'slug': '%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87', 'permalink': 'http://starcase.ir/product/%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87/', 'date_created': '2024-04-24T19:22:43', 'date_created_gmt': '2024-04-24T14:52:43', 'date_modified': '2024-04-24T19:22:45', 'date_modified_gmt': '2024-04-24T14:52:45', 'type': 'variable', 'status': 'publish', 'featured': False, 'catalog_visibility': 'visible', 'description': '', 'short_description': '', 'sku': '', 'price': '', 'regular_price': '', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'purchasable': False, 'total_sales': 0, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'external_url': '', 'button_text': '', 'tax_status': 'taxable', 'tax_class': '', 'manage_stock': False, 'stock_quantity': None, 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'low_stock_amount': None, 'sold_individually': False, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_required': True, 'shipping_taxable': True, 'shipping_class': '', 'shipping_class_id': 0, 'reviews_allowed': True, 'average_rating': '0', 'rating_count': 0, 'upsell_ids': [], 'cross_sell_ids': [], 'parent_id': 0, 'purchase_note': '', 'categories': [{'id': 15, 'name': 'دسته بندی نشده', 'slug': 'uncategorized'}], 'tags': [], 'images': [{'id': 22529, 'date_created': '2024-04-24T23:52:42', 'date_created_gmt': '2024-04-24T14:52:42', 'date_modified': '2024-04-24T23:52:43', 'date_modified_gmt': '2024-04-24T14:52:43', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/1dc52f-10.jpeg', 'name': '1dc52f-10.jpeg', 'alt': ''}, {'id': 22531, 'date_created': '2024-04-24T23:52:43', 'date_created_gmt': '2024-04-24T14:52:43', 'date_modified': '2024-04-24T23:52:43', 'date_modified_gmt': '2024-04-24T14:52:43', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/e7220b-10.jpeg', 'name': 'e7220b-10.jpeg', 'alt': ''}, {'id': 22532, 'date_created': '2024-04-24T23:52:44', 'date_created_gmt': '2024-04-24T14:52:44', 'date_modified': '2024-04-24T23:52:44', 'date_modified_gmt': '2024-04-24T14:52:44', 'src': 'http://starcase.ir/wp-content/uploads/2024/04/549b69-10.jpeg', 'name': '549b69-10.jpeg', 'alt': ''}], 'attributes': [], 'default_attributes': [], 'variations': [], 'grouped_products': [], 'menu_order': 0, 'price_html': '', 'related_ids': [21512, 20144], 'meta_data': [], 'stock_status': 'outofstock', 'has_options': True, 'post_password': '', 'permalink_template': 'http://starcase.ir/product/%pagename%/', 'generated_slug': 'قاب-piggy-سیلیکونی-برجسته', '_links': {'self': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530'}], 'collection': [{'href': 'http://starcase.ir/wp-json/wc/v3/products'}]}}
and second problem is that i can’t make a variation for my product according to these documentation
i use these code
print(woocommerceApi.post("products/22530/variations", data).json())
<code>data = {
"regular_price": "9.00",
"attributes": [
{
"id": 5,
"option": "Black"
}
]}
print(woocommerceApi.post("products/22530/variations", data).json())
</code>
data = {
"regular_price": "9.00",
"attributes": [
{
"id": 5,
"option": "Black"
}
]}
print(woocommerceApi.post("products/22530/variations", data).json())
and get these result
<code>{'id': 22533, 'date_created': '2024-04-24T19:24:29', 'date_created_gmt': '2024-04-24T14:54:29', 'date_modified': '2024-04-24T19:24:29', 'date_modified_gmt': '2024-04-24T14:54:29', 'description': '', 'permalink': 'http://starcase.ir/product/%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87/', 'sku': '', 'price': '9.00', 'regular_price': '9.00', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'status': 'publish', 'purchasable': True, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'tax_status': 'taxable', 'tax_class': 'parent', 'manage_stock': False, 'stock_quantity': None, 'stock_status': 'instock', 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'low_stock_amount': None, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_class': '', 'shipping_class_id': 0, 'image': None, 'attributes': [], 'menu_order': 0, 'meta_data': [], 'name': '', 'parent_id': 22530, '_links': {'self': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530/variations/22533'}], 'collection': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530/variations'}], 'up': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530'}]}}
<code>{'id': 22533, 'date_created': '2024-04-24T19:24:29', 'date_created_gmt': '2024-04-24T14:54:29', 'date_modified': '2024-04-24T19:24:29', 'date_modified_gmt': '2024-04-24T14:54:29', 'description': '', 'permalink': 'http://starcase.ir/product/%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87/', 'sku': '', 'price': '9.00', 'regular_price': '9.00', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'status': 'publish', 'purchasable': True, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'tax_status': 'taxable', 'tax_class': 'parent', 'manage_stock': False, 'stock_quantity': None, 'stock_status': 'instock', 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'low_stock_amount': None, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_class': '', 'shipping_class_id': 0, 'image': None, 'attributes': [], 'menu_order': 0, 'meta_data': [], 'name': '', 'parent_id': 22530, '_links': {'self': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530/variations/22533'}], 'collection': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530/variations'}], 'up': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530'}]}}
</code>
{'id': 22533, 'date_created': '2024-04-24T19:24:29', 'date_created_gmt': '2024-04-24T14:54:29', 'date_modified': '2024-04-24T19:24:29', 'date_modified_gmt': '2024-04-24T14:54:29', 'description': '', 'permalink': 'http://starcase.ir/product/%d9%82%d8%a7%d8%a8-piggy-%d8%b3%db%8c%d9%84%db%8c%da%a9%d9%88%d9%86%db%8c-%d8%a8%d8%b1%d8%ac%d8%b3%d8%aa%d9%87/', 'sku': '', 'price': '9.00', 'regular_price': '9.00', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'status': 'publish', 'purchasable': True, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'tax_status': 'taxable', 'tax_class': 'parent', 'manage_stock': False, 'stock_quantity': None, 'stock_status': 'instock', 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'low_stock_amount': None, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_class': '', 'shipping_class_id': 0, 'image': None, 'attributes': [], 'menu_order': 0, 'meta_data': [], 'name': '', 'parent_id': 22530, '_links': {'self': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530/variations/22533'}], 'collection': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530/variations'}], 'up': [{'href': 'http://starcase.ir/wp-json/wc/v3/products/22530'}]}}
it seems create a variation but it doesn’t show on product in admin panel or product page in website
tnx in advanced
i try documentation and all the answers found in stackoverflow ,github and stackexchange