fixed attachment issue

This commit is contained in:
TheLeo 2024-10-07 13:45:13 +00:00
parent 452efb92b7
commit 8db8ab0a48

View File

@ -31,6 +31,7 @@ def makeCall (target, verb, key, payload= None, files= None):
return responseData return responseData
except requests.exceptions.HTTPError as http_error: except requests.exceptions.HTTPError as http_error:
print(f'{RED}HTTP Error:{RESET}\n{http_error}') print(f'{RED}HTTP Error:{RESET}\n{http_error}')
pint(f'Reponse Content: {response.content}')
raise raise
except Exception as error: except Exception as error:
print(f'{RED}Error:{RESET}\n{error}') print(f'{RED}Error:{RESET}\n{error}')
@ -40,7 +41,7 @@ def makeCall (target, verb, key, payload= None, files= None):
if files == None: if files == None:
response = requests.post(target, auth=(key, 'X'), json= payload) response = requests.post(target, auth=(key, 'X'), json= payload)
else: else:
response = requests.post(target, data= payload, auth=(key, 'X'), files= files) response = requests.post(target, data=payload, auth=(key, 'X'), files= files)
if response.status_code != 429: if response.status_code != 429:
response.raise_for_status() response.raise_for_status()
responseData = response.json() responseData = response.json()
@ -52,6 +53,7 @@ def makeCall (target, verb, key, payload= None, files= None):
return responseData return responseData
except requests.exceptions.HTTPError as http_error: except requests.exceptions.HTTPError as http_error:
print(f'{RED}HTTP Error:{RESET}\n{http_error}') print(f'{RED}HTTP Error:{RESET}\n{http_error}')
print(f'Reponse Content: {response.content}')
raise raise
except Exception as error: except Exception as error:
print(f'{RED}Error:{RESET}\n{error}') print(f'{RED}Error:{RESET}\n{error}')
@ -182,12 +184,12 @@ for i, ticket in enumerate(ticketArray['results']):
attachments = {} attachments = {}
anim = ['', '', '', ''] anim = ['', '', '', '']
ticketData = makeCall(sourceDom + f'/api/v2/tickets/{ticket["id"]}?include=conversations,requester', 'get', sourceKey) ticketData = makeCall(sourceDom + f'/api/v2/tickets/{ticket["id"]}?include=conversations,requester', 'get', sourceKey)
if 'attachments' in ticket: if 'attachments' in ticketData:
for x, attachment in enumerate(ticket['attachments']): for attachment in ticketData['attachments']:
if attachment.get('attachment_url'): if attachment.get('attachment_url'):
fileRes = requests.get(attachment.attachment_url) fileRes = requests.get(attachment['attachment_url'])
if fileRes.status_code == 200: if fileRes.status_code == 200:
attachments[x] = (attachment['name'], fileRes.content) attachments['attachments[]'] = (attachment['name'], fileRes.content)
else: else:
print(f'{RED}File Error:{RESET}\nFailed to download {attachment["name"]}') print(f'{RED}File Error:{RESET}\nFailed to download {attachment["name"]}')
payload = { payload = {
@ -200,7 +202,7 @@ for i, ticket in enumerate(ticketArray['results']):
'description': ticketData["description"], 'description': ticketData["description"],
'source': ticketData["source"], 'source': ticketData["source"],
} }
newTicket = makeCall(destDom + '/api/v2/tickets', 'post', destKey, payload, files=attachments if attachments else None) newTicket = makeCall(destDom + '/api/v2/tickets', 'post', destKey, payload, attachments if attachments else None)
## Gaterhing conversation history from ticketData, and then updating the ticket to include them in a private note ## Gaterhing conversation history from ticketData, and then updating the ticket to include them in a private note
if len(ticketData['conversations']) > 0: if len(ticketData['conversations']) > 0:
@ -234,12 +236,4 @@ for i in range(5, 0, -1):
print(f'Exiting in {i} seconds...') print(f'Exiting in {i} seconds...')
time.sleep(1) time.sleep(1)
clear(1) clear(1)
sys.exit(0) sys.exit(0)