API - Recommended way to delete all products?

91 views
Skip to first unread message

C G

unread,
Apr 29, 2021, 9:04:47 AM4/29/21
to cloud-recommendations-users
Hi,
batch import of products is supported and works. But how do I delete all products from the catalog via the API? Do I really have to call a delete product request for all products in the catalog? 
What's the recommended way to write a custom product importer, scheduled on a daily basis? My naive approach would be: delete catalog/all_products, then batch_import products on a daily basis.
Thanks in advance,
christian

Muhammad Ahmad

unread,
May 1, 2021, 7:01:36 PM5/1/21
to C G, cloud-recommendations-users
Hi Chris Here is the details of deleting and uploading products via API.
You can make a loop to call the API and delete all your products one by one. Few days back when i wanted to delete all products I was told I will have to delete them on by one. So I created a script for my self in python.
first of all create an auth token by entering this in your terminal
gcloud auth application-default print-access-token

and copy this token to use in authorization header

here is pythoncode

import pandas as pd
import requests as re

url = "https://retail.googleapis.com/v2/projects/<projectname>/locations/global/catalogs/default_catalog/branches/0/products/"

headers = { 'Authorization': 'Bearer generatedToken'}

df = pd.read_excel("/home/abubakar/Downloads/Documents/Product Data.xls")

# (df['id'].iloc[0])
try:

for i in df['id']:
res = re.delete(url=url+i ,headers=headers)
print(res)

except Exception as e :
print("Not deleted",e)


--
You received this message because you are subscribed to the Google Groups "cloud-recommendations-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-recommendatio...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-recommendations-users/a90271fa-9554-4548-a510-716b0d748cedn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages