Add redirect link to Woocommerce deleted product by Python API

42 Views Asked by At

I use Python Woocommerce library for managing a testing Wordpress shop. After creating codes for adding new products with multithreading and storing ID, SKU, categories and attributes, Image ID and... in CSV files, I have encountered a problem for handling duplicated products.

With IDs that are stored in CSV files, its possible to delete product by this line:

from woocommerce import API
wcapi = API(
    url="...",
    consumer_key="...",
    consumer_secret="...",
    wp_api = True,
    version="wc/v3",
    timeout=120,
    query_string_auth=True)

id_ = ...
response = wcapi.delete(f"products/{id_}", params={"force": True})

It works, but How can Redirect removed duplicated products to main products (301 redirect)?


By requests library it's possible to delete a post by this:

import requests
website = ...
wp_api = 'wp-json/wp/v2/product'
id_ = ...
response = requests.delete(f"{website}/{wp_api}/{id_}", auth=(username, password), timeout=60)

But I couldn't find a way for my problem. Should I use requests.put() and define redirect for main product or something else?

0

There are 0 best solutions below