Last active
September 23, 2024 12:05
-
-
Save fabiensebban/445048d4b9c3067b03828cdd9dd4c408 to your computer and use it in GitHub Desktop.
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 argparse # Library for parsing command-line arguments | |
import requests | |
import json | |
import logging # Library for logging messages | |
# Parsing command-line arguments | |
parser = argparse.ArgumentParser(description='Remove all variants from a given instance') | |
parser.add_argument('--instance', type=str, help='SubDomain of your QuablePIM', required=True) | |
parser.add_argument('--token', type=str, help='Access Token with full permissions', required=True) | |
args = parser.parse_args() | |
pimUrl = "bellerose" | |
headers = { | |
'Authorization': 'Bearer {}'.format(args.token) # Authorization header with access token | |
} | |
documentCodeCollection = [ "document_code_1", "document_code_2" ] # TODO : replace by documents' code to remove | |
documentLinkCodeCollection = [ "link_code" ] # TODO : replace by link code | |
documentPayload = json.dumps({ | |
"mode" : "replace", | |
"items": [] | |
}) | |
try: | |
for documentCode in documentCodeCollection: | |
for documentLinkCode in documentLinkCodeCollection: | |
urldocumentLink = "https://{}.quable.com/api_1.php/documents/{}/links/{}".format(pimUrl, documentCode, documentLinkCode) | |
try: | |
print("URL Document Link - {}".format(urldocumentLink)) | |
mediaResponse = requests.request("POST", urldocumentLink, headers=headers, data=documentPayload) | |
mediaResponse.raise_for_status() | |
except requests.exceptions.HTTPError as errh: | |
print(errh) | |
except requests.exceptions.HTTPError as errh: | |
print(errh) | |
except requests.exceptions.ConnectionError as errc: | |
print(errc) | |
except requests.exceptions.Timeout as errt: | |
print(errt) | |
except requests.exceptions.TooManyRedirects as errm: | |
print(errm) | |
except requests.exceptions.RequestException as err: | |
print(err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment