GetDataCollectionLink
Generates the URL for a Data Collection Task into Context. Can be used to get the url for tasks send via Email, Slack, or even if you select "By Task Only". To generate links for specific users, add an array of users in the users argument.
python · Common Scripts
Source
from base64 import b64encode import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 def generate_url(server_url: str, encoded_task: str, encoded_user: str) -> str: """Generates a data collection URL. Args: server_url: The Demisto server URL. encoded_task: The encoded task ID. encoded_user: The encoded user ID. Returns: The data collection URL. """ if is_xsiam_or_xsoar_saas(): try: otp = execute_command("generateOTP", {}) except Exception as err: if "Unsupported Command" in str(err): return f"{server_url}/#/external/form/{encoded_task}/{encoded_user}" raise err return f"{server_url}/external/form/{encoded_task}/{encoded_user}?otp={otp}" return f"{server_url}/#/external/form/{encoded_task}/{encoded_user}" def encode_string(value: str) -> str: b64 = b64encode(value.encode("ascii")) return b64.hex() def get_data_collection_url(task_id: str, users: List[str]) -> List[dict[str, str]]: demisto_urls = demisto.demistoUrls() server_url = demisto_urls.get("server", "") incident_id = demisto.incident().get("id") task = f"{incident_id}@{task_id}" encoded_task = encode_string(task) urls = [] for user in users: encoded_user = encode_string(user) urls.append( { "user": user, "task": task, "url": generate_url(server_url, encoded_task, encoded_user), } ) return urls def get_data_collection_url_command(args: dict[str, Any]) -> CommandResults: # pragma: no cover task_id = args.get("task_id", None) if not task_id: raise ValueError("task_id not specified") users = argToList(args.get("users", [])) if not users: raise ValueError("users not specified") result = get_data_collection_url(task_id, users) return CommandResults(outputs_prefix="DataCollectionURL", outputs_key_field="user", outputs=result, ignore_auto_extract=True) def main(): # pragma: no cover try: return_results(get_data_collection_url_command(demisto.args())) except Exception as ex: return_error(f"Failed to execute GetDataCollectionLink. Error: {ex!s}") if __name__ in ("__main__", "__builtin__", "builtins"): main()
README
Generates the URL for a Data Collection Task into Context. Can be used to get the url for tasks send via Email, Slack, or even if you select “By Task Only”.
To generate links for specific users, add an array of users in the users argument.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | Utility |
Inputs
| Argument Name | Description |
|---|---|
| task_id | The data collection task ID. |
| users | The array of users the data collection task was sent to, or that you want to send to (If using by task only) |
Outputs
| Path | Description | Type |
|---|---|---|
| DataCollectionURL.url | The data collection URL | String |
| DataCollectionURL.task | The task ID for the generated URL | Unknown |
| DataCollectionURL.user | The user for which the data collection link was generated | Unknown |