Delete PIM product
import requests
import json
def get_all_products_from_pim():
url_update = 'https://pim-client.wizart.ai/api/customer/articles?page=1'
headers = {
'Accept': 'application/json',
'Authorization': access_token
}
get_uploaded_products = requests.get(url_update, headers=headers, timeout=None)
uploaded_products = json.loads(get_uploaded_products.text)
total_num_page = uploaded_products['meta']['last_page'] #get all pages
for page_num in range(1, total_num_page + 1):
try:
url_get_exist_product = f'https://pim-client.wizart.ai/api/customer/articles?page={page_num}&locale=en'
get_exist_product = requests.get(url_get_exist_product, headers=headers, timeout=None)
all_uploaded_products = json.loads(get_exist_product.text)
info_uploaded_products = all_uploaded_products['data']
page_num = page_num + 1
time.sleep(2)
except:
pass
return info_uploaded_products
all_products_pim = get_all_products_from_pim()
def delete_product():
for products_pim in all_products_pim:
product_uuid = products_pim['uuid']
collection_uuid = products_pim['collection']['uuid']
url = f'https://pim-client.wizart.ai/api/v2/collection/{collection_uuid}/articles/'
headers = {
'Authorization': access_token,
'Content-Type': 'application/json'
}
data = {
'data': {
'type': 'products',
'id': f'{product_uuid}'
}
}
response = requests.delete(url, headers=headers, json=data)
delete_product()
The
get_all_products_from_pim()
function is defined. It retrieves all the uploaded products from the PIM system by making GET requests to the specified API endpoint. The function iterates through all the pages of products, storing the retrieved product information in theinfo_uploaded_products
variable.The
delete_product()
function is defined. It iterates over the retrieved product information stored inall_products_pim
. For each product, it extracts the UUID and collection UUID. Then, it constructs the URL for deleting the product from the specified collection.Inside the loop, a DELETE request is made using the
requests
library. The URL, headers, and data payload (in JSON format) are specified. The UUID of the product to be deleted is included in the payload.The product deletion is performed by sending the DELETE request to the API endpoint.