View file File name : delete_all_products.py Content :from google.oauth2 import service_account from googleapiclient.discovery import build from googleapiclient.errors import HttpError import requests # === Setup === SERVICE_ACCOUNT_FILE = '/Users/romirkapoor/Desktop/Quicklly/quicklly-merchant-center-copy.json' SCOPES = ['https://www.googleapis.com/auth/content'] merchant_id = '5616033984' credentials = service_account.Credentials.from_service_account_file( SERVICE_ACCOUNT_FILE, scopes=SCOPES ) service = build('content', 'v2.1', credentials=credentials) # === Delete All Products and Update Crawl Status === def delete_all_products_batch(): try: request = service.products().list(merchantId=merchant_id) all_products = [] while request is not None: response = request.execute() all_products.extend(response.get('resources', [])) request = service.products().list_next(request, response) print(f"Total products to delete: {len(all_products)}") chunk_size = 500 # max for batch for i in range(0, len(all_products), chunk_size): batch = all_products[i:i + chunk_size] entries = [] for idx, product in enumerate(batch): entries.append({ 'batchId': i + idx, 'merchantId': merchant_id, 'method': 'delete', 'productId': product['id'] }) batch_request = {'entries': entries} response = service.products().custombatch(body=batch_request).execute() for entry in response.get('entries', []): batch_id = entry['batchId'] product_id = next((e['productId'] for e in entries if e['batchId'] == batch_id), 'Unknown') if 'errors' in entry: print(f"[Failed] {product_id}: {entry['errors']}") else: print(f"[Success] Deleted: {product_id}") # === Update crawl status === try: offer_id = product_id.split(":")[-1] crawl_response = requests.post( "https://devrestapi.goquicklly.com/updateProductCrowlStatus", json={"offerid": offer_id} ) print(f"Updated crawl status for {offer_id}: {crawl_response.json()}") except Exception as e: print(f"Failed to update crawl status for {offer_id}: {e}") except HttpError as e: print(f"HTTP error during batch deletion: {e}") except Exception as e: print(f"Unexpected error: {e}") delete_all_products_batch()