Summary

The createEmailAction() mutation creates a stored, reusable email action in a LogScale view. Email actions send notifications to one or more recipients when triggered by a legacy alert, aggregate alert, filter alert, or scheduled search. A single email action can be associated with multiple alerts and scheduled searches. An email action does not trigger on its own; associate it with an alert or scheduled search to activate it.

Recipients can be static email addresses or message template expressions that resolve field values at trigger time, for example {field:email}. Each unique resolved address receives a separate notification. When using template expressions for recipients, scope the triggering query so that each recipient receives only events relevant to them.

Syntax

graphql
createEmailAction(
      input: CreateEmailAction!
   ): EmailAction!

The mutation accepts a single required input argument of type CreateEmailAction. Provide the view name, action name, recipient list, and proxy setting at minimum. The subject, body, CSV attachment flag, and labels are optional.

The mutation returns a non-null EmailAction object. The returned object includes the unique action identifier, which you need to reference the action in subsequent mutations and queries.

Example

Raw
graphql
mutation {
  createEmailAction(input:
      { viewName: "humio",
        name: "my-mail-act",
        recipients: ["bob@company.com"],
        useProxy: false
      } )
  { id, recipients }
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "mutation {
  createEmailAction(input:
      { viewName: \"humio\",
        name: \"my-mail-act\",
        recipients: [\"bob@company.com\"],
        useProxy: false
      } )
  { id, recipients }
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "mutation {
  createEmailAction(input:
      { viewName: \"humio\",
        name: \"my-mail-act\",
        recipients: [\"bob@company.com\"],
        useProxy: false
      } )
  { id, recipients }
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "mutation { ^
  createEmailAction(input: ^
      { viewName: \"humio\", ^
        name: \"my-mail-act\", ^
        recipients: [\"bob@company.com\"], ^
        useProxy: false ^
      } ) ^
  { id, recipients } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createEmailAction(input:
      { viewName: \"humio\",
        name: \"my-mail-act\",
        recipients: [\"bob@company.com\"],
        useProxy: false
      } )
  { id, recipients }
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "mutation {
  createEmailAction(input:
      { viewName: \"humio\",
        name: \"my-mail-act\",
        recipients: [\"bob@company.com\"],
        useProxy: false
      } )
  { id, recipients }
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
my $req = HTTP::Request->new("POST", $uri );

$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "mutation {
  createEmailAction(input:
      { viewName: \"humio\",
        name: \"my-mail-act\",
        recipients: [\"bob@company.com\"],
        useProxy: false
      } )
  { id, recipients }
}"
}'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {"query" : "mutation {
  createEmailAction(input:
      { viewName: \"humio\",
        name: \"my-mail-act\",
        recipients: [\"bob@company.com\"],
        useProxy: false
      } )
  { id, recipients }
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  path: 'graphql',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
Example Responses
Success (HTTP Response Code 200 OK)
json
{
  "data": {
    "createEmailAction": {
      "id": "abc123",
      "recipients": [
        "bob@company.com"
      ]
    }
  }
}

Input Parameters

The viewName and name fields identify the target repository and the action's display name respectively. The recipients list accepts static email addresses or message template expressions using {field:fieldname} syntax; each unique resolved address receives a separate notification. Set useProxy to true to route outgoing email through the HTTP proxy configured for the LogScale instance. The subjectTemplate and bodyTemplate fields accept the same {field:fieldname} template syntax to interpolate event field values at trigger time; a null value causes LogScale to use the default system template. The attachCsvFile flag, when true, attaches a CSV file of matching events to the notification. The following table describes each input field in the CreateEmailAction type:

Table: CreateEmailAction Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
attachCsvBoolean  Long-Term Whether the result set should be attached as a CSV file.
bodyTemplateString  Long-Term The body of the email. Can be templated with values from the result.
labelsStringyes Long-Term A set of labels by which to categorize the action.
nameStringyes Long-Term The name of the action.
recipientsStringyes Long-Term A list of email addresses where to send an email.
subjectTemplateString  Long-Term The subject of the email. Can be templated with values from the result.
useProxyBooleanyes Long-Term Whether the action should use the configured proxy to make web requests.
viewNameStringyes Long-Term The name of the view or repository to which the action is attached.

Returned Values

The mutation returns an EmailAction object representing the newly created action. The returned object includes the action's unique identifier, name, recipient list, template fields, labels, proxy setting, and audit timestamps. Retrieve the id field to reference this action in subsequent mutations such as updateEmailAction() or deleteActionV2().

Table: EmailAction Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
allowedActions[AssetAction]yes Short-Term The allowed asset actions. See AssetAction . This is a preview feature. Changes may occur.
attachCsvbooleanyes Long-Term Whether the result set should be attached as a CSV file.
bodyTemplatestring  Long-Term Body of the email. Can be templated with values from the result.
createdInfoAssetCommitMetadata  Long-Term Metadata related to the creation of the action. See AssetCommitMetadata.
displayNamestringyes Long-Term The display name of the action.
idstringyes Long-Term The unique identifier of the action.
isAllowedToRunbooleanyes Long-Term False if this type of action is disabled because of a security policy.
labels[string]  Preview The labels associated with the action, if any.
modifiedInfoAssetCommitMetadata  Long-Term Metadata related to the latest modification of the action. See AssetCommitMetadata.
namestringyes Long-Term The name of the action.
packagePackageInstallation  Long-Term The package which the action is part. See PackageInstallation.
packageIdVersionedPackageSpecifier  Long-Term The package version. VersionedPackageSpecifier is a scalar.
recipients[string]yes Long-Term List of email addresses to send an email.
requiresOrganizationOwnedQueriesPermissionToEditbooleanyes Long-Term True if this action is used by triggers, where the query is run by the organization. If true, then the OrganizationOwnedQueries permission is required to edit the action.
resourcestringyes Short-Term The resource identifier for the action.
subjectTemplatestring  Long-Term Subject of the email. Can be templated with values from the result.
useProxybooleanyes Long-Term Defines whether the action should use the configured proxy to make web requests.
yamlTemplateYAMLyes Long-Term A template that can be used to recreate the action. YAML is a scalar.