# Notification Template Management using Spyctl

To learn more about what Notification Templates are, see [Notification Templates](https://docs.spyderbat.com/concepts/notifications/notification-templates)

## Prerequisites

If you have never used Spyctl start [here](https://docs.spyderbat.com/installation/spyctl) to learn how to install it, then follow the [Initial Configuration](https://docs.spyderbat.com/installation/spyctl) guide.

## What are Notification Templates?

Notification Templates define the format of notifications sent via different channels such as Email, Slack, Webhook, and PagerDuty. These templates help in customizing the notification messages. You can either specify a Notification Target or a Notification Template that map specific targets to templates.

**Available Notification Template Types:**

1. email - Create an email notification template.
2. pagerduty - Create a PagerDuty notification template.
3. slack - Create a Slack notification template.
4. webhook - Create a webhook notification template.

## Managing Notification Templates

### Create

To create a new Notification Template, use the create command:

Note: This will only create a local YAML file for you to edit. It makes no immediate changes to your Spyderbat environment.

```sh
 spyctl create notification-template [TYPE] -n NAME
```

For example:

```sh
 spyctl create notification-template slack -n slack-template > template.yaml
```

This will create a default Slack Notification Template and save it to a file called template.yaml.

```yaml
apiVersion: spyderbat/v1
kind: NotificationTemplate
metadata:
  name: Example
  type: slack
spec:
  text: ''
  blocks: []
```

To get the template in JSON format use `-o json` option:

```
 spyctl create notification-template slack -n slack-template -o json > template.yaml
```

Note: Learn How to populate the Template field values [here](https://docs.spyderbat.com/concepts/notifications/notification-templates)

### Apply

To make a Notification Template available for use, apply it using the apply command:

```
 spyctl apply -f FILENAME
```

For example:

```
 spyctl apply -f template.yaml
```

### Get or Download

You can use the get command to view or download your Notification Templates.

```sh
 spyctl get notification-templates
```

For example:

```sh
 spyctl get notification-templates
```

```
Getting notification-templates
Page 1/1
NAME                 UID                        TYPE       CREATED                     DESCRIPTION
test-email-tmpl      tmpl:avgUE                 email      2024-09-30T21:06:03 UTC     Operations teams.
```

To download a Notification Template as YAML or JSON, use the -o option:

```sh
 spyctl get notification-templates -o yaml slack-template
```

Using the > character, you can save the document to a file:

```sh
 spyctl get notification-templates -o yaml slack-template > template.yaml
```

### Edit

To modify an existing Notification Template, use the edit command:

```sh
spyctl edit notification-template NAME_OR_UID
```

For example:

```sh
 spyctl edit notification-template slack-template
```

This will open the template in your configured text editor for modification.

### Delete

To remove a Notification Template from the Spyderbat system, use the delete command:

```sh
spyctl delete notification-template <NAME_OR_UID>
```

For example:

```sh
spyctl delete notification-template slack-template
```
