How to add input select actions using Rest

I have written a powershell file that when initiated sends input select options based on files in a folder on my PC. Now, I want to just add an action for each option. How do I change this script to do so?

# Import the System.Net.WebClient namespace for making HTTP requests
using namespace System.Net

# Import the System.Web.Script.Serialization namespace for JSON serialization
using namespace System.Web.Script.Serialization

# Import the System.Text namespace for encoding JSON data
using namespace System.Text

# Create an empty array to store the formatted names
$formattedNames = @()

# Get the .bat files from the specified directory
$items = Get-ChildItem -Path "C:\signalRGB_backup\theme bats" | Where-Object { $_.Name -like "*.bat" -and $_.Name -notlike "restart-signal.bat" -and $_.Name -notlike "startup.bat" -and $_.Name -notlike "Previous.bat" }

# Enumerate the .bat files
foreach ($item in $items) {
    # Replace hyphens and underscores with spaces, and capitalize the first letter of each word
    $formattedName = (Get-Culture).TextInfo.ToTitleCase(($item.BaseName -replace '-', ' '))

    $fileName = $item.Name

    # Output the formatted filename
    Write-Host "$formattedName | ($fileName)"

    # Add the formatted name to the array
    $formattedNames += $formattedName
}

# Convert the array of formatted names to JSON
$jsonOptions = $formattedNames | ConvertTo-Json -Compress

# Set up the REST API endpoint for Home Assistant
$baseUrl = "https://WEBSITE:PORT/api/services/input_select/set_options"

$AccessKey = "XXXX"

# Define the headers for the HTTP request
$headers = @{
    "Authorization" = "Bearer $AccessKey";
    "Content-Type" = "application/json";
}

# Define the payload for the HTTP request
$data = @{
    "entity_id" = "input_select.signalrgb_themes_selection";
    "options" = $jsonOptions | ConvertFrom-Json;
}

# Convert the payload to JSON
$jsonData = $data | ConvertTo-Json -Depth 1

# Make the HTTP request to update the options of the input_select entity
$response = Invoke-WebRequest -Uri $baseUrl -Method POST -Headers $headers -Body $jsonData

# Output the response
Write-Host "Response: $($response.StatusCode) $($response.StatusDescription)"

What do you think an action represents on an input select helper?

Do you mean you want to dynamically update an automation or script that runs when an option is chosen on the dashboard?

What I want to actually do is automate it to have the action field per item. Because the files change every so often, I don’t want to manually make another yaml config for a specific file.

Still not clear what you mean. Give an example.

It may be clear in your mind, but without the context and background there are too many possibilities for what you could be trying to do.

Where is the input select? On a dashboard?

What “action” are we talking about? Do you mean what you want to happen when you manually select the option from the dashboard?

What sort of things will the action do?

Well that script up there automatically scans a folder on my pc and then creates an array of filenames to HA. This array is then broken down via javascript to insert the filename titles as an option in an input select. If that folder changes, the array changes as well. Now I can manually go into my yaml, and create an automation per title made, but if that folder structure changes then I have an invalid config for a non existant entity. I would like it so maybe if I modify that script that each item in that array is automatically configured in yaml (or database entry) has an automation made for it. Maybe something like upload (item-filename.yaml) into the /automations/ folder with some preset attributes ready to be modified. Then, if that file is removed from the folder that this script scans, delete it from /automations/ because it no longer exists to connect to.