Skip to main content

Hi,

In a custom action i have the following code:

siemplify.add_attachment(file_path=file_name,description=comment,is_favorite=True)
 
The file is attached to the case wall, but the "description" is not visible and the attachment is not marked as a favourite? I've looked at the github for the sdk (url/screenshot below) and i'm confused as to why the attachment is not showing as a favorite. 
 
 

 

Hey @af27,

Depending on how you implemented the Custom Action, it could be a variety of reasons. I had a quick look at the requests and responses that the manual action uses for adding attachments with favourites and the action itself does not seem to work, even though the parameter is set to true and it returns a successful response. Quick note, the manual action uses a lower case boolean (true) so that may be worth a try.

Since it's a custom action, you could call the actual endpoint which the GUI uses instead of relying on the is_favorite parameter: 

 

https://URL.com/api/external/v1/dynamic-cases/SetFavouriteWallRecordRequst?format=camel

 

If you do that, the parameter name is different (isFavorite instead of is_favorite)

 

{"type":3,"recordId":ID,"isFavorite":true}

 

 

 

 


Hey @af27,

Depending on how you implemented the Custom Action, it could be a variety of reasons. I had a quick look at the requests and responses that the manual action uses for adding attachments with favourites and the action itself does not seem to work, even though the parameter is set to true and it returns a successful response. Quick note, the manual action uses a lower case boolean (true) so that may be worth a try.

Since it's a custom action, you could call the actual endpoint which the GUI uses instead of relying on the is_favorite parameter: 

 

https://URL.com/api/external/v1/dynamic-cases/SetFavouriteWallRecordRequst?format=camel

 

If you do that, the parameter name is different (isFavorite instead of is_favorite)

 

{"type":3,"recordId":ID,"isFavorite":true}

 

 

 

 


yes it seems like the isFavorite is ignored... I got round this in the end by writing this function that will add an attachment, a comment and favourite it.

 

from SiemplifyDataModel import Attachment

def upload_file(siemplify, file_path,file_description):
#create an attachment object, note: is_favorite does not appear to actually do anything
att = Attachment.fromfile(path=file_path,
case_id=siemplify.case_id,alert_identifier=siemplify.alert_id,
description=file_description,is_favorite=True)

#url which the sdk uses make the reequest
url = f"{siemplify.API_ROOT}/external/v1/sdk/AddAttachment?format=snake"
r = siemplify.session.post(url, json=att.__dict__)
if r.status_code == 200:
#the response appears to just be an INT
comment_id = r.text
else:
raise Exception(f"Failed to upload file to SOAR: {r.text}")

#convert the response to an int, if it fails download all comments on the case and get the id
#of the most recent comment (in theory this should be the attachment but there is a chance it isn't)
try:
comment_int = int(comment_id)
except Exception as err:
print(err)
comments = siemplify.get_case_comments()
comment = comments[-1]
comment_int = comment['id']

#make api call to update as favourite
url = f"{siemplify.API_ROOT}/external/v1/cases/wall/favourite"
body = {
"isFavorite": True,
"recordId":comment_int,
"type": 5,
"activityKind": 1
}

r = siemplify.session.patch(url, json=body)
if r.status_code != 200:
raise Exception(f"Failed to set comment to favourite {r.text}")

 


Reply