NBoomackClient
Show / Hide Table of Contents

Action Management

Managing actions encompasses the following interactions:

  • Listing all action IDs
  • Getting the definition of an action
  • Creating or updating an action
  • Deleting an action

Make sure you understand the difference between actions and action types, before you use the API. You can learn more about actions and action types in the documentation.

Important: Managing actions through the HTTP API is deactivated by default for security reasons. To activate action management you need to start the Boomack Server with the configuration option api.enable.actions=true.

The following examples assume you already have a configured BoomackClient instance in the variable client. See Get Started if you do not know how to configure a BoomackClient instance.

List Action IDs

The method GetActionIds() returns a IdListResponse, which is an enumerable of strings.

var response = await client.GetActionIds();
foreach (var id in response)
{
    Console.WriteLine("- " + id);
}

Get Action

The method GetAction(string) returns a BoomackActionResponse.

var response = await client.GetAction("my-action");
var action = response.Action;
Console.WriteLine("Action Type: {0}", action.Type);
if (action is ShellAction shellAction)
{
    Console.WriteLine("Command: {0}", shellAction.Command);
    Console.WriteLine("Arguments: {0}", string.Join(" ", shellAction.Args));
}

Create or Update Action

On the HTTP API level of the Boomack Server, creating and updating are the same operation. Both are implemented by an HTTP PUT request.

To make the code using this client library more readable, however, two methods are available that do the same thing in the background:

  • AddAction(string, BoomackAction)
  • UpdateAction(string, BoomackAction)

For action type from core plug-in:

var action = new ShellAction()
{
    Command = "mysql", // call the MySQL client CLI
    Args = new[] {
        "--host=localhost", "--port=3306",
        "--user=me", "--password=SECRET",
        "--batch", // do not use history file
        "--html", // produce HTML output
        "--skip-pager", // disable paging
    },
    // pass the payload of the action as SQL script
    Payload = ShellActionPayloadMode.STDIN,
};
await client.AddAction("my-action", action);

For action type from additional plug-in:

var action = new BoomackAction("mqtt");

// treat action definition as dictionary
action["connectUrl"] = "mqtt://127.0.0.1:1883";
// use the dynamic wrapper for prettier code
var actionWrapper = action.DynamicWrapper;
actionWrapper.Topic = "demo/dotnet";

await client.AddAction("my-action", action);

Delete Action

For the deletion of an action you just need the action ID.

await client.DeleteAction("my-action");

Next: Export

In This Article
Back to top
Boomack Homepage