# diagrid notification destination create

Create a notification destination

### Description

Create a notification destination.

A destination is the sink a matched notification is delivered to. It is
reusable: several notification routes may name the same destination.

The flags a destination takes depend on its --type. The webhook flags are
prefixed --webhook-.

\--webhook-auth-token sets the bearer token sent with every delivery. The token
is moved into the project's secret store on the way in: it is not kept on the
destination and reading the destination back never returns it.

By default the body is the notification serialized as JSON. The
\--webhook-body-template flag renders it instead, with the notification as the
template data: .Type, .Labels, .Message and .Timestamp. Pipe every interpolated
value through the json function so the body stays valid whatever the value
contains.

By default any 2xx response is a successful delivery. Some endpoints answer 2xx
and report a failure in the JSON body instead. --webhook-check-field sets
what a successful response body looks like:

field=value  the field has that value, as Slack's Web API sets ok=true
field=       the field is missing, null or empty, as an endpoint that adds
an error object only on failure

Any other body, including one that is not JSON, fails the delivery.
\--webhook-check-message names the field whose value is reported as
the reason. Fields are dot-separated paths, such as result.status.

```
diagrid notification destination create <name> [flags]
```

### Examples

```

  # An unauthenticated webhook
  diagrid notification destination create ops-webhook \
    --webhook-url https://hooks.example.com/catalyst

  # A webhook authenticated with a bearer token
  diagrid notification destination create ops-webhook \
    --webhook-url https://hooks.example.com/catalyst \
    --webhook-auth-token s3cr3t

  # Add a header the receiver expects
  diagrid notification destination create ops-webhook \
    --webhook-url https://hooks.example.com/catalyst \
    --webhook-header X-Diagrid-Source:catalyst

  # Shape the body for a chat webhook
  diagrid notification destination create slack \
    --webhook-url https://hooks.slack.com/services/... \
    --webhook-body-template '{"text": {{ .Message | json }}}'

  # Post through Slack's Web API, which reports failures in the body
  diagrid notification destination create slack \
    --webhook-url https://slack.com/api/chat.postMessage \
    --webhook-auth-token xoxb-... \
    --webhook-body-template '{"channel": "C0123456789", "text": {{ .Message | json }}}' \
    --webhook-check-field ok=true \
    --webhook-check-message error

  # Fail deliveries whose response carries an error object
  diagrid notification destination create alerts-api \
    --webhook-url https://api.example.com/alerts \
    --webhook-check-field error= \
    --webhook-check-message error.message

```

### Options

```
  -p, --project string                 Name of existing project
      --type string                    Destination channel (default "webhook")
      --webhook-url string             Endpoint each matching notification is POSTed to
      --webhook-auth-token string      Bearer token sent with every delivery; stored in the project's secret store
      --webhook-header stringArray     Extra request header as Name:value; repeat for several. Content-Type and Authorization are set by the destination and cannot be configured.
      --webhook-body-template string   Go text template rendering the request body from the notification (.Type, .Labels, .Message, .Timestamp). Omit to send the notification as JSON.
      --webhook-check-field string     Deliver only when this field of the JSON response body has this value, as field=value (for Slack's Web API: ok=true). field= with no value delivers only when the field is missing, null or empty (for an error field present only on failure: error=)
      --webhook-check-message string   Field of the JSON response body whose value is reported as the failure reason (for Slack's Web API: error)
  -h, --help                           help for create
```

### Options inherited from parent commands

```
      --api-key string   Diagrid Cloud API key
```

### SEE ALSO

- [diagrid notification destination](./destination.md)	 - Manage notification destinations
