forked from atlassian-api/atlassian-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_desk.py
903 lines (760 loc) · 31.6 KB
/
service_desk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
# coding=utf-8
import logging
from .rest_client import AtlassianRestAPI
log = logging.getLogger(__name__)
class ServiceDesk(AtlassianRestAPI):
"""
JIRA ServiceDesk API object
"""
# Information actions
def get_info(self):
"""Get info about Service Desk app"""
return self.get("rest/servicedeskapi/info", headers=self.experimental_headers)
def get_service_desks(self):
"""
Returns all service desks in the Jira Service Desk application
with the option to include archived service desks
:return: Service Desks
"""
service_desks_list = self.get(
"rest/servicedeskapi/servicedesk",
headers=self.experimental_headers,
)
if self.advanced_mode:
return service_desks_list
else:
return (service_desks_list or {}).get("values")
def get_service_desk_by_id(self, service_desk_id):
"""
Returns the service desk for a given service desk ID
:param service_desk_id: str
:return: Service Desk
"""
return self.get(
"rest/servicedeskapi/servicedesk/{}".format(service_desk_id),
headers=self.experimental_headers,
)
# Customers actions
def create_customer(self, full_name, email):
"""
Creating customer user.
:param full_name: str - full name
:param email: str - email address
:return: New customer
"""
log.warning("Creating customer...")
data = {"fullName": full_name, "email": email}
return self.post(
"rest/servicedeskapi/customer",
headers=self.experimental_headers,
data=data,
)
def get_customer_request(self, issue_id_or_key):
"""
Get single request
:param issue_id_or_key: str
:return: Customer request
"""
return self.get(
"rest/servicedeskapi/request/{}".format(issue_id_or_key),
headers=self.experimental_headers,
)
def get_my_customer_requests(self):
"""Returning requests where you are the assignee"""
response = self.get("rest/servicedeskapi/request", headers=self.experimental_headers)
if self.advanced_mode:
return response
return (response or {}).get("values")
def create_customer_request(
self,
service_desk_id,
request_type_id,
values_dict,
raise_on_behalf_of=None,
request_participants=None,
):
"""
Creating customer request
:param service_desk_id: str
:param request_type_id: str
:param values_dict: str/dict
:param raise_on_behalf_of: str
:param request_participants: list
:return: New request
"""
log.info("Creating request...")
data = {
"serviceDeskId": service_desk_id,
"requestTypeId": request_type_id,
"requestFieldValues": values_dict,
}
if raise_on_behalf_of:
data["raiseOnBehalfOf"] = raise_on_behalf_of
if request_participants:
data["requestParticipants"] = request_participants
param_map = {"headers": self.experimental_headers}
if isinstance(values_dict, dict):
param_map["json"] = data
elif isinstance(values_dict, str):
param_map["data"] = data
return self.post("rest/servicedeskapi/request", **param_map)
def get_customer_request_status(self, issue_id_or_key):
"""
Get customer request status name
:param issue_id_or_key: str
:return: Status name
"""
request = self.get(
"rest/servicedeskapi/request/{}/status".format(issue_id_or_key),
headers=self.experimental_headers,
)
if self.advanced_mode:
return request
if request:
if request.get("values", []):
return request.get("values", [])[0].get("status", {})
return {}
def get_customer_transitions(self, issue_id_or_key):
"""
Returns a list of transitions that customers can perform on the request
:param issue_id_or_key: str
:return:
"""
url = "rest/servicedeskapi/request/{}/transition".format(issue_id_or_key)
return self.get(url, headers=self.experimental_headers)
def get_request_types(self, service_desk_id):
"""
Gets request types
:param service_desk_id: str
:return: all service desk request types
"""
return self.get(
"rest/servicedeskapi/servicedesk/{}/requesttype".format(service_desk_id),
headers=self.experimental_headers,
)
# Participants actions
def get_request_participants(self, issue_id_or_key, start=0, limit=50):
"""
Get request participants
:param issue_id_or_key: str
:param start: OPTIONAL: int
:param limit: OPTIONAL: int
:return: Request participants
"""
url = "rest/servicedeskapi/request/{}/participant".format(issue_id_or_key)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
response = self.get(url, params=params, headers=self.experimental_headers)
if self.advanced_mode:
return response
return (response or {}).get("values")
def add_request_participants(self, issue_id_or_key, users_list):
"""
Add users as participants to an existing customer request
The calling user must have permission to manage participants for this customer request
:param issue_id_or_key: str
:param users_list: list
:return:
"""
url = "rest/servicedeskapi/request/{}/participant".format(issue_id_or_key)
data = {"usernames": users_list}
return self.post(url, data=data, headers=self.experimental_headers)
def remove_request_participants(self, issue_id_or_key, users_list):
"""
Remove participants from an existing customer request
The calling user must have permission to manage participants for this customer request
:param issue_id_or_key: str
:param users_list: list
:return:
"""
url = "rest/servicedeskapi/request/{}/participant".format(issue_id_or_key)
data = {"usernames": users_list}
return self.delete(url, data=data, headers=self.experimental_headers)
# Transitions actions
def perform_transition(self, issue_id_or_key, transition_id, comment=None):
"""
Perform a customer transition for a given request and transition ID.
An optional comment can be included to provide a reason for the transition.
:param issue_id_or_key: str
:param transition_id: str
:param comment: OPTIONAL: str
:return: None
"""
log.warning("Performing transition...")
data = {"id": transition_id, "additionalComment": {"body": comment}}
url = "rest/servicedeskapi/request/{}/transition".format(issue_id_or_key)
return self.post(url, headers=self.experimental_headers, data=data)
# Comments actions
def create_request_comment(self, issue_id_or_key, body, public=True):
"""
Creating request comment
:param issue_id_or_key: str
:param body: str
:param public: OPTIONAL: bool (default is True)
:return: New comment
"""
log.info("Creating comment...")
data = {"body": body, "public": public}
url = "rest/servicedeskapi/request/{}/comment".format(issue_id_or_key)
return self.post(path=url, data=data, headers=self.experimental_headers)
def get_request_comments(self, issue_id_or_key, start=0, limit=50, public=True, internal=True):
"""
Get all comments in issue
:param issue_id_or_key: str
:param start: OPTIONAL: int
:param limit: OPTIONAL: int
:param public: OPTIONAL: bool
:param internal: OPTIONAL: bool
:return: Issue comments
"""
url = "rest/servicedeskapi/request/{}/comment".format(issue_id_or_key)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
if public is not None:
params["public"] = bool(public)
if internal is not None:
params["internal"] = bool(internal)
response = self.get(url, params=params, headers=self.experimental_headers)
if self.advanced_mode:
return response
return (response or {}).get("values")
# return self.get(
# "rest/servicedeskapi/request/{}/comment".format(issue_id_or_key),
# headers=self.experimental_headers,
# )
def get_request_comment_by_id(self, issue_id_or_key, comment_id):
"""
Get single comment by ID
:param issue_id_or_key: str
:param comment_id: str
:return: Single comment
"""
return self.get(
"rest/servicedeskapi/request/{}/comment/{}".format(issue_id_or_key, comment_id),
headers=self.experimental_headers,
)
# Organizations actions
def get_organisations(self, service_desk_id=None, start=0, limit=50):
"""
Returns a list of organizations in the Jira instance. If the user is not an agent,
the resource returns a list of organizations the user is a member of.
:param service_desk_id: OPTIONAL: str Get organizations from single Service Desk
:param start: OPTIONAL: int The starting index of the returned objects.
Base index: 0. See the Pagination section for more details.
:param limit: OPTIONAL: int The maximum number of users to return per page.
Default: 50. See the Pagination section for more details.
:return:
"""
url_without_sd_id = "rest/servicedeskapi/organization"
url_with_sd_id = "rest/servicedeskapi/servicedesk/{}/organization".format(service_desk_id)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
if service_desk_id is None:
return self.get(
url_without_sd_id,
headers=self.experimental_headers,
params=params,
)
return self.get(url_with_sd_id, headers=self.experimental_headers, params=params)
# add alias for spelling consistency
get_organizations = get_organisations
def get_organization(self, organization_id):
"""
Get an organization for a given organization ID
:param organization_id: str
:return: Organization
"""
url = "rest/servicedeskapi/organization/{}".format(organization_id)
return self.get(url, headers=self.experimental_headers)
def get_users_in_organization(self, organization_id, start=0, limit=50):
"""
Get all the users of a specified organization
:param organization_id: str
:param start: OPTIONAL: int
:param limit: OPTIONAL: int
:return: Users list in organization
"""
url = "rest/servicedeskapi/organization/{}/user".format(organization_id)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
return self.get(url, headers=self.experimental_headers, params=params)
def create_organization(self, name):
"""
To create an organization Jira administrator global or agent
permission is required depending on the settings
:param name: str
:return: Organization data
"""
log.warning("Creating organization...")
url = "rest/servicedeskapi/organization"
data = {"name": name}
return self.post(url, headers=self.experimental_headers, data=data)
def add_organization(self, service_desk_id, organization_id):
"""
Adds an organization to a servicedesk for a given servicedesk ID and organization ID
:param service_desk_id: str
:param organization_id: int
:return:
"""
log.warning("Adding organization...")
url = "rest/servicedeskapi/servicedesk/{}/organization".format(service_desk_id)
data = {"organizationId": organization_id}
return self.post(url, headers=self.experimental_headers, data=data)
def remove_organization(self, service_desk_id, organization_id):
"""
Removes an organization from a servicedesk for a given servicedesk ID and organization ID
:param service_desk_id: str
:param organization_id: int
:return:
"""
log.warning("Removing organization...")
url = "rest/servicedeskapi/servicedesk/{}/organization".format(service_desk_id)
data = {"organizationId": organization_id}
return self.delete(url, headers=self.experimental_headers, data=data)
def delete_organization(self, organization_id):
"""
Deletes an organization for a given organization ID
:param organization_id:
:return:
"""
log.warning("Deleting organization...")
url = "rest/servicedeskapi/organization/{}".format(organization_id)
return self.delete(url, headers=self.experimental_headers)
def add_users_to_organization(self, organization_id, users_list=[], account_list=[]):
"""
Adds users to an organization
users_list is a list of strings
account_list is a list of accountIds
:param account_list:
:param organization_id: str
:param users_list: list
:return:
"""
log.warning("Adding users...")
url = "rest/servicedeskapi/organization/{}/user".format(organization_id)
data = {"usernames": users_list, "accountIds": account_list}
return self.post(url, headers=self.experimental_headers, data=data)
def remove_users_from_organization(self, organization_id, users_list=[], account_list=[]):
"""
Removes users from an organization
users_list is a list of strings
account_list is a list of accountIds
:param organization_id: str
:param users_list: list
:param account_list: list
:return:
"""
log.warning("Removing users...")
url = "rest/servicedeskapi/organization/{}/user".format(organization_id)
data = {"usernames": users_list, "accountIds": account_list}
return self.delete(url, headers=self.experimental_headers, data=data)
# Attachments actions
def create_attachments(
self,
service_desk_id,
issue_id_or_key,
filenames,
public=True,
comment=None,
):
"""
Add attachment as a comment.
Setting attachment visibility is dependent on the user's permission. For example,
Agents can create either public or internal attachments,
while Unlicensed users can only create internal attachments,
and Customers can only create public attachments.
An additional comment may be provided which will be prepended to the attachments.
:param service_desk_id: str
:param issue_id_or_key: str
:param filenames: Union(List[str], str), name, if file in current directory or full path to file
:param public: OPTIONAL: bool (default is True)
:param comment: OPTIONAL: str (default is None)
:return: Request info
"""
# Create temporary attachment
temp_attachment_ids = []
if not isinstance(filenames, list):
filenames = [filenames]
for filename in filenames:
temp_attachment_id = self.attach_temporary_file(service_desk_id, filename)
temp_attachment_ids.append(temp_attachment_id)
# Add attachments
return self.add_attachments(issue_id_or_key, temp_attachment_ids, public, comment)
def create_attachment(
self,
service_desk_id,
issue_id_or_key,
filename,
public=True,
comment=None,
):
"""
Add attachment as a comment.
Setting attachment visibility is dependent on the user's permission. For example,
Agents can create either public or internal attachments,
while Unlicensed users can only create internal attachments,
and Customers can only create public attachments.
An additional comment may be provided which will be prepended to the attachments.
:param service_desk_id: str
:param issue_id_or_key: str
:param filename: str, name, if file in current directory or full path to file
:param public: OPTIONAL: bool (default is True)
:param comment: OPTIONAL: str (default is None)
:return: Request info
"""
log.info("Creating attachment...")
return self.create_attachments(
service_desk_id,
issue_id_or_key,
filename,
public=public,
comment=comment,
)
def attach_temporary_file(self, service_desk_id, filename):
"""
Create temporary attachment, which can later be converted into permanent attachment
:param service_desk_id: str
:param filename: str
:return: Temporary Attachment ID
"""
url = "rest/servicedeskapi/servicedesk/{}/attachTemporaryFile".format(service_desk_id)
# no application/json content type and an additional X-Atlassian-Token header
# https://docs.atlassian.com/jira-servicedesk/REST/4.14.1/#servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile-attachTemporaryFile
experimental_headers = self.experimental_headers.copy()
del experimental_headers["Content-Type"]
experimental_headers["X-Atlassian-Token"] = "no-check"
with open(filename, "rb") as file:
# 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
def add_attachments(self, issue_id_or_key, temp_attachment_ids, public=True, comment=None):
"""
Adds temporary attachment to customer request using attach_temporary_file function
:param issue_id_or_key: str
:param temp_attachment_ids: List[str], ID from result attach_temporary_file function
:param public: bool (default is True)
:param comment: str (default is None)
:return:
"""
data = {
"temporaryAttachmentIds": temp_attachment_ids,
"public": public,
"additionalComment": {"body": comment},
}
url = "rest/servicedeskapi/request/{}/attachment".format(issue_id_or_key)
return self.post(url, headers=self.experimental_headers, data=data)
def add_attachment(self, issue_id_or_key, temp_attachment_id, public=True, comment=None):
"""
Adds temporary attachment to customer request using attach_temporary_file function
:param issue_id_or_key: str
:param temp_attachment_id: str, ID from result attach_temporary_file function
:param public: bool (default is True)
:param comment: str (default is None)
:return:
"""
log.info("Adding attachment")
return self.add_attachments(
issue_id_or_key,
[temp_attachment_id],
public=public,
comment=comment,
)
# SLA actions
def get_sla(self, issue_id_or_key, start=0, limit=50):
"""
Get the SLA information for a customer request for a given request ID or key
A request can have zero or more SLA values
IMPORTANT: The calling user must be an agent
:param issue_id_or_key: str
:param start: OPTIONAL: int
:param limit: OPTIONAL: int
:return: SLA information
"""
url = "rest/servicedeskapi/request/{}/sla".format(issue_id_or_key)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
response = self.get(url, params=params, headers=self.experimental_headers)
if self.advanced_mode:
return response
return (response or {}).get("values")
def get_sla_by_id(self, issue_id_or_key, sla_id):
"""
Get customer request SLA information for given request ID or key and SLA metric ID
IMPORTANT: The calling user must be an agent
:param issue_id_or_key: str
:param sla_id: str
:return: SLA information
"""
url = "rest/servicedeskapi/request/{0}/sla/{1}".format(issue_id_or_key, sla_id)
return self.get(url, headers=self.experimental_headers)
def sla_rebuild(self, tickets=None):
"""
Fix corrupted or missing sla
https://confluence.atlassian.com/jirakb/missing-or-corrupted-sla-data-in-jira-service-management-828790603.html
:param tickets: list of tickets like [XXX-123, XXX-124]
:return:
"""
if tickets is None:
tickets = []
url = "rest/servicedesk/1/servicedesk/sla/admin/task/destructive/reconstruct"
return self.post(url, data=tickets)
# Approvals
def get_approvals(self, issue_id_or_key, start=0, limit=50):
"""
Get all approvals on a request, for a given request ID/Key
:param issue_id_or_key: str
:param start: OPTIONAL: int
:param limit: OPTIONAL: int
:return:
"""
url = "rest/servicedeskapi/request/{}/approval".format(issue_id_or_key)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
response = self.get(url, headers=self.experimental_headers, params=params)
if self.advanced_mode:
return response
return (response or {}).get("values")
def get_approval_by_id(self, issue_id_or_key, approval_id):
"""
Get an approval for a given approval ID
:param issue_id_or_key: str
:param approval_id: str
:return:
"""
url = "rest/servicedeskapi/request/{0}/approval/{1}".format(issue_id_or_key, approval_id)
return self.get(url, headers=self.experimental_headers)
def answer_approval(self, issue_id_or_key, approval_id, decision):
"""
Answer a pending approval
:param issue_id_or_key: str
:param approval_id: str
:param decision: str
:return:
"""
url = "rest/servicedeskapi/request/{0}/approval/{1}".format(issue_id_or_key, approval_id)
data = {"decision": decision}
return self.post(url, headers=self.experimental_headers, data=data)
def get_queue_settings(self, project_key):
"""
Get queue settings on project
:param project_key: str
:return:
"""
url = "rest/servicedeskapi/queues/{}".format(project_key)
return self.get(url, headers=self.experimental_headers)
def get_customers(self, service_desk_id, query=None, start=0, limit=50):
"""
Returns a list of the customers on a service desk.
The returned list of customers can be filtered using the query parameter.
The parameter is matched against customers' displayName, name, or email.
For example, searching for "John", "Jo", "Smi", or "Smith" will match a
user with display name "John Smith"..
:param query:
:param start:
:param limit:
:param service_desk_id: str
:return: the customers added to the service desk
"""
url = "rest/servicedeskapi/servicedesk/{}/customer".format(service_desk_id)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
if query is not None:
params["query"] = query
return self.get(url, headers=self.experimental_headers, params=params)
def add_customers(self, service_desk_id, list_of_usernames=[], list_of_accountids=[]):
"""
Adds one or more existing customers to the given service desk.
If you need to create a customer, see Create customer method.
Administer project permission is required, or agents if public signups
and invites are enabled for the Service Desk project.
:param service_desk_id: str
:param list_of_usernames: list
:param list_of_accountids: list
:return: the customers added to the service desk
"""
url = "rest/servicedeskapi/servicedesk/{}/customer".format(service_desk_id)
data = {
"usernames": list_of_usernames,
"accountIds": list_of_accountids,
}
log.info("Adding customers...")
return self.post(url, headers=self.experimental_headers, data=data)
def remove_customers(self, service_desk_id, list_of_usernames=[], list_of_accountids=[]):
"""
Removes one or more customers from a service desk. The service
desk must have closed access. If any of the passed customers are
not associated with the service desk, no changes will be made for
those customers and the resource returns a 204 success code.
:param service_desk_id: str
:param list_of_usernames: list
:param list_of_accountids: list
:return: the customers added to the service desk
"""
url = "rest/servicedeskapi/servicedesk/{}/customer".format(service_desk_id)
data = {
"usernames": list_of_usernames,
"accountIds": list_of_accountids,
}
log.info("Removing customers...")
return self.delete(url, headers=self.experimental_headers, data=data)
def get_queues(self, service_desk_id, include_count=False, start=0, limit=50):
"""
Returns a page of queues defined inside a service desk, for a given service desk ID.
The returned queues will include issue counts for each queue (issueCount field)
if the query param includeCount is set to true (default=false).
Permissions: The calling user must be an agent of the given service desk.
:param service_desk_id: str
:param include_count: bool
:param start: int
:param limit: int
:return: a page of queues
"""
url = "rest/servicedeskapi/servicedesk/{}/queue".format(service_desk_id)
params = {}
if include_count is not None:
params["includeCount"] = bool(include_count)
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
return self.get(url, headers=self.experimental_headers, params=params)
def get_issues_in_queue(self, service_desk_id, queue_id, start=0, limit=50):
"""
Returns a page of issues inside a queue for a given queue ID.
Only fields that the queue is configured to show are returned.
For example, if a queue is configured to show only Description and Due Date,
then only those two fields are returned for each issue in the queue.
Permissions: The calling user must have permission to view the requested queue,
i.e. they must be an agent of the service desk that the queue belongs to.
:param service_desk_id: str
:param queue_id: str
:param start: int
:param limit: int
:return: a page of issues
"""
url = "rest/servicedeskapi/servicedesk/{0}/queue/{1}/issue".format(service_desk_id, queue_id)
params = {}
if start is not None:
params["start"] = int(start)
if limit is not None:
params["limit"] = int(limit)
return self.get(url, headers=self.experimental_headers, params=params)
def get_plugins_info(self):
"""
Provide plugins info
:return a json of installed plugins
"""
url = "rest/plugins/1.0/"
return self.get(url, headers=self.no_check_headers, trailing=True)
def get_plugin_info(self, plugin_key):
"""
Provide plugin info
:return a json of installed plugins
"""
url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
return self.get(url, headers=self.no_check_headers, trailing=True)
def get_plugin_license_info(self, plugin_key):
"""
Provide plugin license info
:return a json specific License query
"""
url = "rest/plugins/1.0/{plugin_key}-key/license".format(plugin_key=plugin_key)
return self.get(url, headers=self.no_check_headers, trailing=True)
def upload_plugin(self, plugin_path):
"""
Provide plugin path for upload into Jira e.g. useful for auto deploy
:param plugin_path:
:return:
"""
files = {"plugin": open(plugin_path, "rb")}
upm_token = self.request(
method="GET",
path="rest/plugins/1.0/",
headers=self.no_check_headers,
trailing=True,
).headers["upm-token"]
url = "rest/plugins/1.0/?token={upm_token}".format(upm_token=upm_token)
return self.post(url, files=files, headers=self.no_check_headers)
def delete_plugin(self, plugin_key):
"""
Delete plugin
:param plugin_key:
:return:
"""
url = "rest/plugins/1.0/{}-key".format(plugin_key)
return self.delete(url)
def check_plugin_manager_status(self):
url = "rest/plugins/latest/safe-mode"
return self.request(method="GET", path=url, headers=self.safe_mode_headers)
def update_plugin_license(self, plugin_key, raw_license):
"""
Update license for plugin
:param plugin_key:
:param raw_license:
:return:
"""
app_headers = {
"X-Atlassian-Token": "nocheck",
"Content-Type": "application/vnd.atl.plugins+json",
}
url = "/plugins/1.0/{plugin_key}/license".format(plugin_key=plugin_key)
data = {"rawLicense": raw_license}
return self.put(url, data=data, headers=app_headers)
def create_request_type(
self,
service_desk_id,
request_type_id,
request_name,
request_description,
request_help_text,
):
"""
Creating a request type
:param request_type_id:
:param request_help_text:
:param service_desk_id: str
:param request_name: str
:param request_description: str
"""
log.warning("Creating request type...")
data = {
"issueTypeId": request_type_id,
"name": request_name,
"description": request_description,
"helpText": request_help_text,
}
url = "rest/servicedeskapi/servicedesk/{}/requesttype".format(service_desk_id)
return self.post(url, headers=self.experimental_headers, data=data)