Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
basics = {}
for basic_param in ["Title", "Queue", "Type", "State", "Priority", "CustomerUser"]:
if basic_param in params:
basics[basic_param] = params.get(basic_param)
del(params[basic_param])
else:
raise Exception("Parameter {} was not found. This is required to create a ticket".format(basic_param))
# left over params added to other_basics
other_basics = {}
for k, v in params.items():
if v:
other_basics[k] = v
# build attachments
attachments = []
for attachment in new_attachments:
a = Attachment.create_basic(Content=attachment["content"], ContentType=mimetypes.guess_type(attachment["filename"])[0], Filename=attachment["filename"])
attachments.append(a)
# build dynamic fields
dynamic_fields = list(map(lambda f: DynamicField(**f), new_dynamic_fields))
# create ticket from basics and all other params
new_ticket = Ticket.create_basic(**basics)
new_article = Article(new_article)
new_attachments = attachments
new_dynamic_fields = dynamic_fields
# Create Ticket
ticket_results = client.ticket_create(
ticket=new_ticket,
article=new_article,
attachments=new_attachments,
dynamic_fields=new_dynamic_fields,
**other_basics
if not new_article["ForceNotificationToUserID"]:
del(new_article["ForceNotificationToUserID"])
new_article = Article(new_article)
# Set attachments
if params.get("Attachments"):
new_attachments = params.pop("Attachments")
for attachment in new_attachments:
filename = attachment['filename']
content = attachment['content']
mimetype = mimetypes.guess_type(filename)
attachments.append(Attachment.create_basic(Content=content,
ContentType=
mimetype[0],
Filename=filename))
ticket_id = params.get('TicketID')
del(params["TicketID"])
dynamic_fields = []
for fields in new_dynamic_fields:
dynamic_fields.append(DynamicField(**fields))
# Pending time
if params.get("PendingTime").startswith("0001-01-01"):
del(params['PendingTime'])
else:
# Format date