Created
November 22, 2023 23:20
-
-
Save rosshiga/3ee442975dafee0cac08c9aea4aa089b to your computer and use it in GitHub Desktop.
Vusion Delete for Whole Store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urllib.request, json | |
| import tkinter as tk | |
| from tkinter import simpledialog, messagebox | |
| import tkinter as tk | |
| from tkinter import simpledialog | |
| from tkinter import messagebox | |
| # Function to show warning popup | |
| def show_warning(): | |
| messagebox.showwarning( | |
| "Warning", | |
| "This will remove all items from SES Cloud and ESL will display an error instead of prices. " | |
| "Do not continue unless you have already created and staged batches to reload all items into the store from BR Data." | |
| ) | |
| # Function to get API key | |
| def get_api_key(): | |
| global apikey | |
| apikey = simpledialog.askstring( | |
| "Input", | |
| "Please enter your Vusion Manager Pro API key (Ocp-Apim-Subscription-Key) (not VLink)" | |
| ) | |
| # Function to get Store ID | |
| def get_store_id(): | |
| global storeID | |
| storeID = simpledialog.askstring("Input", "Please enter your SES Store ID") | |
| # Main GUI window | |
| root = tk.Tk() | |
| root.withdraw() # Hide the main window | |
| # Show warning message | |
| show_warning() | |
| # Get API key and Store ID | |
| get_api_key() | |
| get_store_id() | |
| dropAll = [] | |
| try: | |
| url = f"https://api-us.vusion.io/vlink-pro/v1/stores/{storeID}/items/search" | |
| hdr = {'Cache-Control': 'no-cache', "Ocp-Apim-Subscription-Key": apikey} | |
| # Request body | |
| for page in range(1, 100): | |
| print(page) | |
| query = {} | |
| query["page"] = page | |
| query["pageSize"] = 9999 | |
| query["includes"] = "itemId" | |
| query = json.dumps(query) | |
| req = urllib.request.Request(url, headers=hdr, data=bytes(query.encode("utf-8"))) | |
| req.get_method = lambda: 'POST' | |
| response = urllib.request.urlopen(req) | |
| response_data = response.read().decode('utf-8') | |
| parsed_json = json.loads(response_data) | |
| events = parsed_json['values'] | |
| dropItems = [event['itemId'] for event in events] | |
| if len(dropItems) == 0: | |
| print(page) | |
| break | |
| dropAll.append(dropItems) | |
| except Exception as e: | |
| messagebox.showwarning("Warning", "Your API information is not valid " + str(e)) | |
| for itemList in dropAll: | |
| try: | |
| url = f"https://api-us.vusion.io/vlink-pro/v1/stores/{storeID}/items" | |
| # Request body | |
| data = itemList | |
| data = json.dumps(data) | |
| req = urllib.request.Request(url, headers=hdr, data=bytes(data.encode("utf-8"))) | |
| req.get_method = lambda: 'DELETE' | |
| response = urllib.request.urlopen(req) | |
| if response.getcode() !=200: | |
| messagebox.showwarning("Warning", "Contact Ross a critical error has occoured") | |
| except Exception as e: | |
| print(e) | |
| messagebox.showwarning("Completed", "Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment