How to create an email alerting destination using API?

Hi,

I have created email_account (for sending) and email_group (for receiving) using the below APIs;

POST _opendistro/_alerting/destinations/email_accounts
POST _opendistro/_alerting/destinations/email_groups

I have tried using Kibana UI, to create alerting destination by going to Alerting > Destinations > Create destination. But, after clicking “Create” button, nothing is happening, the button will stay inactive for a while and then comes back to active, without doing anything. So, I decided to use API to create destination.

Here, API - Open Distro Documentation its documented how to create slack and webhook destinations using API. Somebody please tell me how to create email destination using API, by providing Name, Type, Sender, and Recipients.

Thanks in advance.

Hi @elasticheart,

Which version of Alerting/Alerting Kibana are you using?

I’d like to validate the destination creation through the Kibana UI, if that’s not working, it would be a bug.

As for the documentation, perhaps it would be helpful to have an example of each destination in the Create destination section.

In the meantime, here is an example of how to create an email Destination through the API (this example has both an email_group and separate email as its recipients).

POST _opendistro/_alerting/destinations
{
  "type": "email",
  "name": "my-email-destination",
  "email": {
    "email_account_id": "YjY7mXMBx015759_IcfW",
    "recipients": [
      {
        "type": "email_group",
        "email_group_id": "YzY-mXMBx015759_dscs"
      },
      {
        "type": "email",
        "email": "example@email.com"
      }
    ]
  }
}

The email_account_id and email_group_id will be the document IDs of the email_account and email_group you have created.

Hi @qreshi,
I’m using 1.11.0 version of alerting i am able to create email destination, how ever is there a way we can pass the ‘Content-Type: test/html’ using API.

I would like to get my alerts in a table format. I tried using mustache with html tags but still i see the text as is which is not rendering to html format.

Any suggestion would be appreciated. Thanks!

I am trying to migrate alert staff from one cluster to another (both are one node clusters). Opendistro 1.11.0. I extracted everything from source cluster using API (created small python script) Now I am testing way to import them into new cluster. I ran test curl comand with admin username/password and some test data for email accounts (it called in kibana GUI) POST command return success with new created email account id. I did search for email accounts and got record about one I just created. Now in GUI I don’t see any . I even creted destination with correct id from email account and email group but still can not see anything in GUI. My thoughts that everything was created using admin account and may be somewhere in admin private tenant? Is there way to add alert staff to particular tenant?