Get Script Code

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

Synopsis

URI
/public_api/v1/scripts/get_script_code/
HTTP Method
POST
Required License
Cortex XDR Pro per Endpoint

Description

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

Request Fields

The body of this request contains a JSON object with the following fields:
Field
Description
request_data
(
Required
) A dictionary containing the API request fields.
script_uid
(
Required
) Unique identifier of the script, returned by the “get scripts” API per script.
Request Example
curl -X POST https://api-{fqdn}/public_api/v1/scripts/get_script_code/ \ -H "x-xdr-auth-id:{API_KEY_ID}" \ -H "Authorization:{API_KEY}" \ -H "Content-Type:application/json" \ -d '{ "request_data":{ "script_uid": "<unique ID>" } }'
Code copied to clipboard
Unable to copy due to lack of browser support.

Success Response

Upon success, the HTTP response code is 200.
Field
Description
reply
JSON object containing the query result.
Success Response Example
{ "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"}
Code copied to clipboard
Unable to copy due to lack of browser support.

Error Response

Upon error, the reply includes an HTTP response code, an error message, and additional information describing the error. The HTTP response code is one of the following:
Field
Description
400
Bad Request. Got an invalid JSON.
401
Unauthorized access. An issue occurred during authentication. This can indicate an incorrect key, id, or other invalid authentication parameters.
402
Unauthorized access. User does not have the required license type to run this API.
403
Forbidden access. The provided API Key does not have the required RBAC permissions to run this API.
500
Internal server error. A unified status for API communication type errors.
Error Response Format
{"reply": {"err_code": STATUS_CODE, "err_msg": GENERAL_MESSAGE, "err_extra": EXTRA_DATA}}
Code copied to clipboard
Unable to copy due to lack of browser support.

Recommended For You