# Pytenable Node for n8n

This node allows you to interact with the Tenable.io API using the `pytenable` Python library.

## Features

-   **UI Mode:** A simple user interface to perform common operations on Tenable.io resources like Scans and Assets.
-   **Code Mode:** A flexible Python code editor that allows you to write custom scripts to interact with the Tenable.io API.
-   **Pre-authenticated `tio` object:** In Code mode, a `tio` object (an instance of `tenable.io.TenableIO`) is pre-authenticated and ready to use.

## Setup

1.  **Credentials:** Before using this node, you need to configure your Tenable.io API credentials in n8n.
    -   Go to the "Credentials" section in your n8n instance.
    -   Click "Add credential".
    -   Search for "Tenable API" and select it.
    -   Fill in your `apikey` and `apisecret`.
    -   Save the credential.

## How to Use

### UI Mode

The UI mode provides a simple way to interact with the Tenable.io API without writing any code.

1.  **Select a Resource:** Choose the Tenable.io resource you want to work with (e.g., Scans, Assets).
2.  **Select an Operation:** Choose the operation you want to perform on the selected resource (e.g., List, Create, Launch).
3.  **Fill in the Parameters:** Provide the necessary parameters for the selected operation.

#### Example: List all scans

-   **Mode:** UI
-   **Resource:** Scans
-   **Operation:** List

This will return a list of all scans in your Tenable.io instance.

#### Example: Create a new scan

-   **Mode:** UI
-   **Resource:** Scans
-   **Operation:** Create
-   **Scan Name:** My New Scan
-   **Targets:** 127.0.0.1

This will create a new basic network scan with the specified name and target.

### Code Mode

The Code mode provides a Python code editor for more advanced use cases.

-   **Pre-authenticated `tio` object:** The `tio` object is an instance of `tenable.io.TenableIO` and is already authenticated with your credentials. You can use it directly in your code.
-   **Input Data:** The input data from the previous node is available in the `items` variable.

#### Example: List all scans and return their names

```python
# The tio object is pre-authenticated and available for use.
# items is a list of input items.

# List all scans
scans = tio.scans.list()

# Extract the names of the scans
scan_names = [{'name': scan['name']} for scan in scans]

# Return the result as a list of items.
return scan_names
```

## Output

The node returns the data directly from the `pytenable` library, formatted as n8n items. Each item in the output array will have a `json` property containing the result from the API.
