Get Script Code

Cortex XDR REST API

post /public_api/v1/scripts/get_script_code

Get the code of a specific script in the script library.

Required license: Cortex XDR Pro per Endpoint or Cortex XDR Pro per GB

Body parameters
request_dataObjectrequired

A dictionary containing the API request fields.

script_uidString

Unique identifier of the script, returned by the Get Scripts API per script.

REQUEST BODY
{ "request_data": { "script_uid": "<unique ID>" } }
CURL
curl -X 'POST'
-H 'Accept: application/json'
-H 'Content-Type: application/json'
'https://api-yourfqdn/public_api/v1/scripts/get_script_code'
-d ''
Responses

Successful response

Body
replyString

JSON object containing the query result.

RESPONSE
{ "reply": "import os\nimport sys\nimport traceback\n\n\ndef run(path, num_levels):\n\tpath = os.path.expanduser(path)\n\tpath = os.path.expandvars(path)\n\treturn scan_directory_recursive(path, num_levels)\n\n\ndef scan_directory_recursive(directory, level):\n\tif level == 0:\n\t\treturn []\n\n\tsubfolders = []\n\ttry:\n\t\twith os.scandir(directory) as entries:\n\t\t\tfor f in entries:\n\t\t\t\ttry:\n\t\t\t\t\tif f.is_dir():\n\t\t\t\t\t\tsubfolders.append(f.path)\n\t\t\t\texcept (OSError,PermissionError):\n\t\t\t\t\tsys.stderr.write(f\"Failed access <{f.path}>\\n\")\n\n\t\tfor folder in list(subfolders):\n\t\t subfolders.extend(scan_directory_recursive(folder, level-1))\n\texcept Exception:\n\t\tsys.stderr.write(f\"Failed scanning directory: <{directory}>, error: {traceback.format_exc()}\")\n\n\treturn subfolders\n" }

Bad Request. Got an invalid JSON.

Body
err_codeString

HTTP response code.

err_msgString

Error message.

Example:{"line": 1, "column": 19, "message": "no viable alternative at input '|alter2'"}
err_extraString

Additional information describing the error.

RESPONSE
{ "err_code": "err_code_example", "err_msg": "{\"line\": 1, \"column\": 19, \"message\": \"no viable alternative at input '|alter2'\"}", "err_extra": "err_extra_example" }

Unauthorized access. An issue occurred during authentication. This can indicate an incorrect key, id, or other invalid authentication parameters.

Body
err_codeString

HTTP response code.

err_msgString

Error message.

Example:{"line": 1, "column": 19, "message": "no viable alternative at input '|alter2'"}
err_extraString

Additional information describing the error.

RESPONSE
{ "err_code": "err_code_example", "err_msg": "{\"line\": 1, \"column\": 19, \"message\": \"no viable alternative at input '|alter2'\"}", "err_extra": "err_extra_example" }

Unauthorized access. User does not have the required license type to run this API.

Body
err_codeString

HTTP response code.

err_msgString

Error message.

Example:{"line": 1, "column": 19, "message": "no viable alternative at input '|alter2'"}
err_extraString

Additional information describing the error.

RESPONSE
{ "err_code": "err_code_example", "err_msg": "{\"line\": 1, \"column\": 19, \"message\": \"no viable alternative at input '|alter2'\"}", "err_extra": "err_extra_example" }

Forbidden access. The provided API Key does not have the required RBAC permissions to run this API.

Body
err_codeString

HTTP response code.

err_msgString

Error message.

Example:{"line": 1, "column": 19, "message": "no viable alternative at input '|alter2'"}
err_extraString

Additional information describing the error.

RESPONSE
{ "err_code": "err_code_example", "err_msg": "{\"line\": 1, \"column\": 19, \"message\": \"no viable alternative at input '|alter2'\"}", "err_extra": "err_extra_example" }

Internal server error. A unified status for API communication type errors.

Body
err_codeString

HTTP response code.

err_msgString

Error message.

Example:{"line": 1, "column": 19, "message": "no viable alternative at input '|alter2'"}
err_extraString

Additional information describing the error.

RESPONSE
{ "err_code": "err_code_example", "err_msg": "{\"line\": 1, \"column\": 19, \"message\": \"no viable alternative at input '|alter2'\"}", "err_extra": "err_extra_example" }