fixed attachment issue
This commit is contained in:
parent
452efb92b7
commit
8db8ab0a48
@ -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}')
|
||||
@ -40,7 +41,7 @@ def makeCall (target, verb, key, payload= None, files= None):
|
||||
if files == None:
|
||||
response = requests.post(target, auth=(key, 'X'), json= payload)
|
||||
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:
|
||||
response.raise_for_status()
|
||||
responseData = response.json()
|
||||
@ -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:
|
||||
@ -234,12 +236,4 @@ for i in range(5, 0, -1):
|
||||
print(f'Exiting in {i} seconds...')
|
||||
time.sleep(1)
|
||||
clear(1)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sys.exit(0)
|
||||
Loading…
x
Reference in New Issue
Block a user