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
except requests.exceptions.HTTPError as http_error:
print(f'{RED}HTTP Error:{RESET}\n{http_error}')
pint(f'Reponse Content: {response.content}')
raise
except Exception as error:
print(f'{RED}Error:{RESET}\n{error}')
@ -52,6 +53,7 @@ def makeCall (target, verb, key, payload= None, files= None):
return responseData
except requests.exceptions.HTTPError as http_error:
print(f'{RED}HTTP Error:{RESET}\n{http_error}')
print(f'Reponse Content: {response.content}')
raise
except Exception as error:
print(f'{RED}Error:{RESET}\n{error}')
@ -182,12 +184,12 @@ for i, ticket in enumerate(ticketArray['results']):
attachments = {}
anim = ['', '', '', '']
ticketData = makeCall(sourceDom + f'/api/v2/tickets/{ticket["id"]}?include=conversations,requester', 'get', sourceKey)
if 'attachments' in ticket:
for x, attachment in enumerate(ticket['attachments']):
if 'attachments' in ticketData:
for attachment in ticketData['attachments']:
if attachment.get('attachment_url'):
fileRes = requests.get(attachment.attachment_url)
fileRes = requests.get(attachment['attachment_url'])
if fileRes.status_code == 200:
attachments[x] = (attachment['name'], fileRes.content)
attachments['attachments[]'] = (attachment['name'], fileRes.content)
else:
print(f'{RED}File Error:{RESET}\nFailed to download {attachment["name"]}')
payload = {
@ -200,7 +202,7 @@ for i, ticket in enumerate(ticketArray['results']):
'description': ticketData["description"],
'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
if len(ticketData['conversations']) > 0:
@ -235,11 +237,3 @@ for i in range(5, 0, -1):
time.sleep(1)
clear(1)
sys.exit(0)