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}')
@ -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:
@ -235,11 +237,3 @@ for i in range(5, 0, -1):
time.sleep(1) time.sleep(1)
clear(1) clear(1)
sys.exit(0) sys.exit(0)