[Service Desk] Creating/Adding attachments
I found a small issue when trying to add an attachment to an active request: When calling the method create_attachment from the ServiceDesk class, the following error is raised: File "/home/thomas/git/private/atlassian-python-api/atlassian/service_desk.py", line 497, in attach_temporary_file .json() AttributeError: 'dict' object has no attribute 'json'.
The error is based on the fact that when using the ServiceDesk class and subsequently the method self.post(...) in normal mode, the response is already converted to JSON inside that method (post). Using the ServiceDesk class in advanced mode does not raise any issues.
I ran into the exact same issue.
As it took me some time what normal & advanced mode means, here to clarify for other people:
Normal mode (via atlassian-python-api pip package): https://atlassian-python-api.readthedocs.io/service_desk.html Advanced mode (via requests to Jira Service REST API): https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-servicedesk/#api-rest-servicedeskapi-servicedesk-servicedeskid-get
Further note: As the advanced mode code example is not complete and doesn't work as is (it just doesn't upload anything), here follows a code example which can successfully upload a file in python:
import requests
service_desk_id=12345
username="username"
api_token="your_api_token"
filename = "filename.xyz"
url = "https://your_service_desk_domain.atlassian.net/rest/servicedeskapi/servicedesk/{service_desk_id}/attachTemporaryFile".format(service_desk_id=service_desk_id)
headers = {
"Accept": "application/json",
# in my testing the authorization header didn't do anything and I had to include the auth parameter in the post request
#"Authorization": "Bearer {api_token}".format(api_token=api_token),
"X-Atlassian-Token": "no-check"
}
files = {
"file": (filename, open(filename, "rb").read(), "multipart/form-data", { "filename": filename })
}
response = requests.post(
url,
headers=headers,
files=files,
auth=(username, api_token)
)
Hi! @skropf thank you for the investigating. I will be happy to see a pull request :)
I have to correct my previous post. The ServiceDesk class has a parameter for advanced mode and it works when setting it to true. A pull request will follow with a fix :)