I am trying to automate the process of shop prices update by using python scripts
The total product count in the shop is 6939. When I use a built-in WooCommerce option to export to csv, I also got the right product count 6939, but when I get all products via API request I get 6923 in total, here is the python code I use:
from woocommerce import API
from openpyxl import *
import time
start_time = time.time()
wcapi = API(
url="*******",
consumer_key="ck_*******",
consumer_secret="cs_*******",
version="wc/v3"
)
products_sorted = {}
page = 1
while True:
products = wcapi.get('products', params={'per_page': 100, 'page': page}).json()
for i in range(0, len(products)):
products_sorted[products[i]['id']] = {
'sku': products[i]['sku'],
'regular_price': products[i]['regular_price'],
'stock_status': products[i]['stock_status'],
'catalog_visibility': products[i]['catalog_visibility'],
}
print(page)
page += 1
if len(products) == 0: # no more products
break
print(len(products_sorted))
Any ideas?