66
77
88class ServiceDesk (AtlassianRestAPI ):
9+ """
10+ JIRA ServiceDesk API object
11+ """
912
1013 # Information actions
1114 def get_info (self ):
@@ -46,7 +49,9 @@ def create_customer(self, full_name, email):
4649 log .warning ('Creating customer...' )
4750 data = {'fullName' : full_name , 'email' : email }
4851
49- return self .post ('rest/servicedeskapi/customer' , headers = self .experimental_headers , data = data )
52+ return self .post ('rest/servicedeskapi/customer' ,
53+ headers = self .experimental_headers ,
54+ data = data )
5055
5156 def get_customer_request (self , issue_id_or_key ):
5257 """
@@ -63,7 +68,8 @@ def get_my_customer_requests(self):
6368
6469 return (self .get ('rest/servicedeskapi/request' ) or {}).get ('values' )
6570
66- def create_customer_request (self , service_desk_id , request_type_id , values_dict , raise_on_behalf_of = None ,
71+ def create_customer_request (self , service_desk_id , request_type_id ,
72+ values_dict , raise_on_behalf_of = None ,
6773 request_participants = None ):
6874 """
6975 Creating customer request
@@ -84,7 +90,7 @@ def create_customer_request(self, service_desk_id, request_type_id, values_dict,
8490
8591 if raise_on_behalf_of :
8692 data ["raiseOnBehalfOf" ] = raise_on_behalf_of
87-
93+
8894 if request_participants :
8995 data ["requestParticipants" ] = request_participants
9096
@@ -97,10 +103,11 @@ def get_customer_request_status(self, issue_id_or_key):
97103 :param issue_id_or_key: str
98104 :return: Status name
99105 """
100- request = (self .get ('rest/servicedeskapi/request/{}/status' .format (issue_id_or_key )) or {}).get ('values' )
101- status = (request [0 ].get ('status' ) or {})
102-
103- return status
106+ request = self .get ('rest/servicedeskapi/request/{}/status' .format (issue_id_or_key ))
107+ if request :
108+ if request .get ('values' , []):
109+ return request .get ('values' , [])[0 ].get ('status' , {})
110+ return {}
104111
105112 def get_customer_transitions (self , issue_id_or_key ):
106113 """
@@ -113,6 +120,16 @@ def get_customer_transitions(self, issue_id_or_key):
113120
114121 return self .get (url , headers = self .experimental_headers )
115122
123+ def get_request_types (self , service_desk_id ):
124+ """
125+ Gets request types
126+
127+ :param service_desk_id: str
128+ :return: all service desk request types
129+ """
130+
131+ return self .get ('rest/servicedeskapi/servicedesk/{}/requesttype' .format (service_desk_id ))
132+
116133 # Participants actions
117134 def get_request_participants (self , issue_id_or_key , start = 0 , limit = 50 ):
118135 """
@@ -189,8 +206,9 @@ def create_request_comment(self, issue_id_or_key, body, public=True):
189206 """
190207 log .warning ('Creating comment...' )
191208 data = {"body" : body , "public" : public }
209+ url = 'rest/servicedeskapi/request/{}/comment' .format (issue_id_or_key )
192210
193- return self .post ('rest/servicedeskapi/request/{}/comment' . format ( issue_id_or_key ) , data = data )
211+ return self .post (path = url , data = data )
194212
195213 def get_request_comments (self , issue_id_or_key ):
196214 """
@@ -211,7 +229,8 @@ def get_request_comment_by_id(self, issue_id_or_key, comment_id):
211229 :return: Single comment
212230 """
213231
214- return self .get ('rest/servicedeskapi/request/{0}/comment/{1}' .format (issue_id_or_key , comment_id ))
232+ return self .get ('rest/servicedeskapi/request/{}/comment/{}' .format (issue_id_or_key ,
233+ comment_id ))
215234
216235 # Organizations actions
217236 def get_organisations (self , service_desk_id = None , start = 0 , limit = 50 ):
@@ -236,8 +255,7 @@ def get_organisations(self, service_desk_id=None, start=0, limit=50):
236255
237256 if service_desk_id is None :
238257 return self .get (url_without_sd_id , headers = self .experimental_headers , params = params )
239- else :
240- return self .get (url_with_sd_id , headers = self .experimental_headers , params = params )
258+ return self .get (url_with_sd_id , headers = self .experimental_headers , params = params )
241259
242260 def get_organization (self , organization_id ):
243261 """
@@ -270,8 +288,8 @@ def get_users_in_organization(self, organization_id, start=0, limit=50):
270288
271289 def create_organization (self , name ):
272290 """
273- To create an organization Jira administrator global permission or agent permission is required
274- depending on the settings
291+ To create an organization Jira administrator global or agent
292+ permission is required depending on the settings
275293
276294 :param name: str
277295 :return: Organization data
@@ -353,13 +371,15 @@ def remove_users_from_organization(self, organization_id, users_list):
353371 return self .delete (url , headers = self .experimental_headers , data = data )
354372
355373 # Attachments actions
356- def create_attachment (self , service_desk_id , issue_id_or_key , filename , public = True , comment = None ):
374+ def create_attachment (self , service_desk_id , issue_id_or_key , filename ,
375+ public = True , comment = None ):
357376 """
358377 Add attachment as a comment.
359378
360379 Setting attachment visibility is dependent on the user's permission. For example,
361- Agents can create either public or internal attachments, while Unlicensed users can only create internal
362- attachments, and Customers can only create public attachments.
380+ Agents can create either public or internal attachments,
381+ while Unlicensed users can only create internal attachments,
382+ and Customers can only create public attachments.
363383
364384 An additional comment may be provided which will be prepended to the attachments.
365385
@@ -390,14 +410,15 @@ def attach_temporary_file(self, service_desk_id, filename):
390410 url = 'rest/servicedeskapi/servicedesk/{}/attachTemporaryFile' .format (service_desk_id )
391411
392412 with open (filename , 'rb' ) as file :
393- result = self .post (url , headers = headers , files = {'file' : file }).get ('temporaryAttachments' )
413+ result = self .post (path = url , headers = headers ,
414+ files = {'file' : file }).get ('temporaryAttachments' )
394415 temp_attachment_id = result [0 ].get ('temporaryAttachmentId' )
395416
396417 return temp_attachment_id
397418
398419 def add_attachment (self , issue_id_or_key , temp_attachment_id , public = True , comment = None ):
399420 """
400- Adds temporary attachment that were created using attach_temporary_file function to a customer request
421+ Adds temporary attachment to customer request using attach_temporary_file function
401422
402423 :param issue_id_or_key: str
403424 :param temp_attachment_id: str, ID from result attach_temporary_file function
@@ -406,11 +427,9 @@ def add_attachment(self, issue_id_or_key, temp_attachment_id, public=True, comme
406427 :return:
407428 """
408429 log .warning ('Adding attachment' )
409- data = {
410- 'temporaryAttachmentIds' : [temp_attachment_id ],
411- 'public' : public ,
412- 'additionalComment' : {'body' : comment }
413- }
430+ data = {'temporaryAttachmentIds' : [temp_attachment_id ],
431+ 'public' : public ,
432+ 'additionalComment' : {'body' : comment }}
414433 url = 'rest/servicedeskapi/request/{}/attachment' .format (issue_id_or_key )
415434
416435 return self .post (url , headers = self .experimental_headers , data = data )
@@ -438,7 +457,7 @@ def get_sla(self, issue_id_or_key, start=0, limit=50):
438457
439458 def get_sla_by_id (self , issue_id_or_key , sla_id ):
440459 """
441- Get the SLA information for a customer request for a given request ID or key and SLA metric ID
460+ Get customer request SLA information for given request ID or key and SLA metric ID
442461 IMPORTANT: The calling user must be an agent
443462
444463 :param issue_id_or_key: str
@@ -525,8 +544,8 @@ def add_customers(self, service_desk_id, list_of_usernames):
525544 def get_queues (self , service_desk_id , include_count = False , start = 0 , limit = 50 ):
526545 """
527546 Returns a page of queues defined inside a service desk, for a given service desk ID.
528- The returned queues will include an issue count for each queue (represented in issueCount field)
529- if the query param includeCount is set to true (defaults to false).
547+ The returned queues will include issue counts for each queue (issueCount field)
548+ if the query param includeCount is set to true (default= false).
530549
531550 Permissions: The calling user must be an agent of the given service desk.
532551
@@ -564,7 +583,8 @@ def get_issues_in_queue(self, service_desk_id, queue_id, start=0, limit=50):
564583 :param limit: int
565584 :return: a page of issues
566585 """
567- url = 'rest/servicedeskapi/servicedesk/{0}/queue/{1}/issue' .format (service_desk_id , queue_id )
586+ url = 'rest/servicedeskapi/servicedesk/{0}/queue/{1}/issue' .format (service_desk_id ,
587+ queue_id )
568588 params = {}
569589
570590 if start is not None :
0 commit comments