bghad1
bghad1

Reputation: 89

how to modify multiple woocommerce products with python

I hope all you guys be fine. I was trying to modify multiple products in Woocommerce with python(Restful Api WooCommerce) here is the code I used:

import sys
import json
from woocommerce import API
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo

wcapi = API(
    url="https://...",
    consumer_key="ck_...",
    consumer_secret="cs_...",
    wp_api = True,
    version="wc/v3",
    query_string_auth=True # Force Basic Authentication as query string true and using under HTTPS
)

data =  {"id":"1995","regular_price":"1775000","sale_price":"1685000","stock_quantity":"6"},
{"id":"4673","regular_price":"2300000","sale_price":"2045000","stock_quantity":"15"}

print(wcapi.put("products/bulk",data).json())

but when I run the code, I got below error:

{'code': 'rest_no_route', 'message': 'No route was found matching the URL and request method', 'data': {'status': 404}}

product IDs are available. before trying to make some changes on bulk, I was able to modify a single product with the below code:

print(wcapi.put("products/1995",data).json())

my current Woocommerce version 3.9 - & - current python version 3.8.1

i was not able to find the solution or why is that happening. how to fix it? also how can i modify multiple variable Woocommerce products?

Thanks

Upvotes: 1

Views: 1698

Answers (1)

bghad1
bghad1

Reputation: 89

finally, the problem got solved. I just wanted to post it here for the future use of others who may face such this problem.

here is the change which I made in the code:

data = {
    "update":
    [ 
    {
        "id":"1995",
        "regular_price":"1775000",
        "sale_price":"1685000",
        "stock_quantity":"6"},
    {
        "id":"4673",
        "regular_price":"2300000",
        "sale_price":"2045000",
        "stock_quantity":"15"}
    ]
}

# Bulk edit of Woocommerce products - here we have 2 sample products
print(wcapi.put("products/batch",data).json())

if you have a better way or think should notice any other thing for working with woocommerce in python, happy to have your post below in this post:-)

Upvotes: 3

Related Questions