6
6
7
7
8
8
class ServiceDesk (AtlassianRestAPI ):
9
+ """
10
+ JIRA ServiceDesk API object
11
+ """
9
12
10
13
# Information actions
11
14
def get_info (self ):
@@ -46,7 +49,9 @@ def create_customer(self, full_name, email):
46
49
log .warning ('Creating customer...' )
47
50
data = {'fullName' : full_name , 'email' : email }
48
51
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 )
50
55
51
56
def get_customer_request (self , issue_id_or_key ):
52
57
"""
@@ -63,7 +68,8 @@ def get_my_customer_requests(self):
63
68
64
69
return (self .get ('rest/servicedeskapi/request' ) or {}).get ('values' )
65
70
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 ,
67
73
request_participants = None ):
68
74
"""
69
75
Creating customer request
@@ -84,7 +90,7 @@ def create_customer_request(self, service_desk_id, request_type_id, values_dict,
84
90
85
91
if raise_on_behalf_of :
86
92
data ["raiseOnBehalfOf" ] = raise_on_behalf_of
87
-
93
+
88
94
if request_participants :
89
95
data ["requestParticipants" ] = request_participants
90
96
@@ -97,10 +103,11 @@ def get_customer_request_status(self, issue_id_or_key):
97
103
:param issue_id_or_key: str
98
104
:return: Status name
99
105
"""
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 {}
104
111
105
112
def get_customer_transitions (self , issue_id_or_key ):
106
113
"""
@@ -113,6 +120,16 @@ def get_customer_transitions(self, issue_id_or_key):
113
120
114
121
return self .get (url , headers = self .experimental_headers )
115
122
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
+
116
133
# Participants actions
117
134
def get_request_participants (self , issue_id_or_key , start = 0 , limit = 50 ):
118
135
"""
@@ -189,8 +206,9 @@ def create_request_comment(self, issue_id_or_key, body, public=True):
189
206
"""
190
207
log .warning ('Creating comment...' )
191
208
data = {"body" : body , "public" : public }
209
+ url = 'rest/servicedeskapi/request/{}/comment' .format (issue_id_or_key )
192
210
193
- return self .post ('rest/servicedeskapi/request/{}/comment' . format ( issue_id_or_key ) , data = data )
211
+ return self .post (path = url , data = data )
194
212
195
213
def get_request_comments (self , issue_id_or_key ):
196
214
"""
@@ -211,7 +229,8 @@ def get_request_comment_by_id(self, issue_id_or_key, comment_id):
211
229
:return: Single comment
212
230
"""
213
231
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 ))
215
234
216
235
# Organizations actions
217
236
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):
236
255
237
256
if service_desk_id is None :
238
257
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 )
241
259
242
260
def get_organization (self , organization_id ):
243
261
"""
@@ -270,8 +288,8 @@ def get_users_in_organization(self, organization_id, start=0, limit=50):
270
288
271
289
def create_organization (self , name ):
272
290
"""
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
275
293
276
294
:param name: str
277
295
:return: Organization data
@@ -353,13 +371,15 @@ def remove_users_from_organization(self, organization_id, users_list):
353
371
return self .delete (url , headers = self .experimental_headers , data = data )
354
372
355
373
# 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 ):
357
376
"""
358
377
Add attachment as a comment.
359
378
360
379
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.
363
383
364
384
An additional comment may be provided which will be prepended to the attachments.
365
385
@@ -390,14 +410,15 @@ def attach_temporary_file(self, service_desk_id, filename):
390
410
url = 'rest/servicedeskapi/servicedesk/{}/attachTemporaryFile' .format (service_desk_id )
391
411
392
412
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' )
394
415
temp_attachment_id = result [0 ].get ('temporaryAttachmentId' )
395
416
396
417
return temp_attachment_id
397
418
398
419
def add_attachment (self , issue_id_or_key , temp_attachment_id , public = True , comment = None ):
399
420
"""
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
401
422
402
423
:param issue_id_or_key: str
403
424
: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
406
427
:return:
407
428
"""
408
429
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 }}
414
433
url = 'rest/servicedeskapi/request/{}/attachment' .format (issue_id_or_key )
415
434
416
435
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):
438
457
439
458
def get_sla_by_id (self , issue_id_or_key , sla_id ):
440
459
"""
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
442
461
IMPORTANT: The calling user must be an agent
443
462
444
463
:param issue_id_or_key: str
@@ -525,8 +544,8 @@ def add_customers(self, service_desk_id, list_of_usernames):
525
544
def get_queues (self , service_desk_id , include_count = False , start = 0 , limit = 50 ):
526
545
"""
527
546
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).
530
549
531
550
Permissions: The calling user must be an agent of the given service desk.
532
551
@@ -564,7 +583,8 @@ def get_issues_in_queue(self, service_desk_id, queue_id, start=0, limit=50):
564
583
:param limit: int
565
584
:return: a page of issues
566
585
"""
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 )
568
588
params = {}
569
589
570
590
if start is not None :
0 commit comments