IBM QRadar SOAR

 View Only

 Artifact Tag

Jump to  Best Answer
Júlio Cirra's profile image
Júlio Cirra posted Thu March 13, 2025 03:48 PM
Hello everyone, I'm having trouble adding a tag to an artifact linked to an incident using the Python API.
 
Does anyone have an example of how I can use an API to do this?
Lucian Sipos's profile image
Lucian Sipos  Best Answer
app_config_path = f"your_app_config_file_path_if_you_plan_to_execute_it_from_your_computer"

class ArgumentParser(resilient.ArgumentParser):
    def __init__(self, config_file=None):
        super(ArgumentParser, self).__init__(config_file=app_config_path)

parser = ArgumentParser(config_file=resilient.get_config_file())
opts = parser.parse_args()
resilient_client = resilient.get_client(opts)

def patch_artifact_tag(incident_id, artifact_id, artifact_tag):
        """
        Add a Tag to an Artifact, creating it if non-existent

        :param incident_id:
        :param artifact_id:
        :param artifact_tag:
        :return: Data dict with results
        """
        soar_tags = resilient_client.get('/tags/data?handle_format=names&exclude_unused=false')['entities']

        tags_dict = {tag['name']: tag['id'] for tag in soar_tags}

        tag_id_list = []

        if artifact_tag not in tags_dict:
            print(f"Tag not available: {artifact_tag}")
            tag_creation = {"display_name": artifact_tag}
            created_tag = resilient_client.post('/tags/data?handle_format=names', tag_creation)
            print(f"Tag created: {created_tag['name']}")
            tag_id_list.append(created_tag['id'])
        else:
            tag_id_list.append(tags_dict[artifact_tag])
            print(f"Tag found: {artifact_tag}")

        global_artifact = resilient_client.get(f'/incidents/{incident_id}/artifacts/{artifact_id}')
        global_artifact = global_artifact['global_artifact'][0]

        for tag_id in tag_id_list:
            new_tag = {"tag_handle": tag_id, "value": None}
            if new_tag not in global_artifact['tags']:
                global_artifact['tags'].append(new_tag)
                print(f"Adding tag {artifact_tag}...")

        updated_artifact = resilient_client.put(f'/artifacts/{global_artifact["id"]}', global_artifact)

        return {global_artifact['id']: updated_artifact}

patch_artifact_tag(incident_id, artifact_id, artifact_tag="TAG_NAME")
Mohamad islam Hamadieh's profile image
Mohamad islam Hamadieh

Hi Julio , 

I haven't tested this before, but it seems you can use the following API.

documentation for it should be on : 

https://yourSOARIP/docs/rest-api/resource_ArtifactREST.html

/orgs/{org_id}/artifacts/{artifact_id}

Yohji Amano's profile image
Yohji Amano

Hello Julio, 

Though I'm not sure the following way is what you expect, ...

In a playbook, which relates to artifact type, just add a script simply to use  [ artifact.addTag("<tag-name>") ]. 

By executing the above playbook, you can add the tag "TEST01" to the artifact as follows:

Júlio Cirra's profile image
Júlio Cirra
Thank you all for your responses!
The script shared by Lucian was perfect.
Thank you very much!!