Skip to content

Commit

Permalink
Jira ServiceDesk: Fix create attachment (#1121)
Browse files Browse the repository at this point in the history
* Jira ServiceDesk: Fix create attachment
In service_desk.py/attach_temporary_file a check was added
to successfully post the request.

* Corrected formatting with black of service_desk.py

* undid wrong black formatting

---------

Co-authored-by: Simon Kropf <simon.kropf@zamg.ac.at>
  • Loading branch information
skropf and Simon Kropf authored Feb 16, 2023
1 parent 056d379 commit 1379a2e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions atlassian/service_desk.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,19 @@ def attach_temporary_file(self, service_desk_id, filename):
experimental_headers["X-Atlassian-Token"] = "no-check"

with open(filename, "rb") as file:
result = (
self.post(path=url, headers=experimental_headers, files={"file": file})
.json()
.get("temporaryAttachments")
)
# bug https://github.com/atlassian-api/atlassian-python-api/issues/1056
# in advanced_mode it returns the raw response therefore .json() is needed
# in normal mode this is not needed and would fail
if self.advanced_mode:
result = (
self.post(path=url, headers=experimental_headers, files={"file": file})
.json()
.get("temporaryAttachments")
)
else:
result = self.post(path=url, headers=experimental_headers, files={"file": file}).get(
"temporaryAttachments"
)
temp_attachment_id = result[0].get("temporaryAttachmentId")

return temp_attachment_id
Expand Down

0 comments on commit 1379a2e

Please sign in to comment.