@@ -51,6 +51,24 @@ def __get_workspace_id(self):
5151 0
5252 ]["workspaceId" ]
5353
54+ def _get_insight_workspace_ids (self ):
55+ """
56+ Returns all Insight workspace Ids.
57+ :return: List
58+ """
59+ result = self .get (
60+ "rest/servicedeskapi/insight/workspace" ,
61+ headers = self .experimental_headers ,
62+ )
63+ return [i ["workspaceId" ] for i in result ["values" ]]
64+
65+ def _get_insight_workspace_id (self ):
66+ """
67+ Returns the first Insight workspace ID.
68+ :return: str
69+ """
70+ return next (iter (self ._get_insight_workspace_ids ()))
71+
5472 # Attachments
5573 def get_attachments_of_objects (self , object_id ):
5674 """
@@ -600,3 +618,27 @@ def get_progress_of_import(self, import_id):
600618 # https://developer.atlassian.com/cloud/insight/rest/api-group-config/#api-config-statustype-id-put
601619 # TODO: Delete config statustype {id}:
602620 # https://developer.atlassian.com/cloud/insight/rest/api-group-config/#api-config-statustype-id-delete
621+
622+ # Update Issue with Insight Field
623+ def update_issue_insight_field (self , key , field_id , insight_keys , add = False ):
624+ """
625+ Set the value of an Insight field.
626+ Args:
627+ key (str): Jira issue key, eg. SFT-446
628+ field_id (str): The internal Jira name of the Insight field, eg. customfield_10200
629+ insight_keys (list): List of Insight objects to associate with the field. Limited
630+ to 20 objects. If the field only takes a single object pass a single value list.
631+ add (bool, optional): Add to the existing field rather than setting the field value.
632+ Defaults to False.
633+ Returns:
634+ [type]: The insight object updated.
635+ """
636+ base_url = self .resource_url ("issue" )
637+ action = "add" if add else "set"
638+ data = {
639+ "update" : {
640+ field_id : [{action : [{"key" : i } for i in insight_keys ]}],
641+ }
642+ }
643+ data = {"fields" : {field_id : [{"key" : i } for i in insight_keys ]}}
644+ return self .put ("{base_url}/{key}" .format (base_url = base_url , key = key ), data = data )
0 commit comments