> ## Documentation Index
> Fetch the complete documentation index at: https://docs.validio.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Up a Channel and Notification Rule

> Create a Slack notification channel and configure a rule to send alerts based on severity.

## Overview

Create a channel to send notifications on, and then add a rule for which notifications are sent on that channel. This recipe uses a Slack channel and a rule that matches on the severity of the incident. A rule can also match on other conditions, such as tags.

> [!NOTE]
>
> When you create, update, or delete an object, you use a `mutation` operation instead of a `query`.

## Steps

**1. Create a channel**

Create a Slack channel, which sends notifications to Slack based on rules. The channel is linked to an existing Slack integration through `integrationId`.

**2. Create a notification rule**

Create a notification rule on the channel. For the available [severities](https://docs.validio.io/api-reference/graphql/types/IncidentSeverity.md) and [conditions](https://docs.validio.io/api-reference/graphql/types/NotificationRuleConfigInput.md), see the [API documentation](https://docs.validio.io/api-reference.md).

## Full code sample

```python title="Python" theme={null}
import os

from validio_sdk.client import Client


async def example():
    client = Client()
    channel_query = """
    mutation ChannelCreate($input: ChannelCreateInput!) {
      channelCreate(input: $input) {
        id
      }
    }
    """
    channel_variables = {
        "input": {
            "name": "slack-channel",
            "namespaceId": os.environ["EXAMPLE_NAMESPACE_ID"],
            "integrationId": os.environ["EXAMPLE_INTEGRATION_ID"],
            "config": {
                "slack": {
                    "slackChannelId": "some-channel-id",
                },
            },
        }
    }
    result = await client.execute(channel_query, variable_values=channel_variables)
    channel_id = result["channelCreate"]["id"]

    rule_query = """
    mutation NotificationRuleCreate($input: NotificationRuleCreateInput!) {
      notificationRuleCreate(input: $input) {
        errors { message }
      }
    }
    """
    rule_variables = {
        "input": {
            "name": "My notification rule",
            "channelId": channel_id,
            "config": {
                "severityCondition": {
                    "severities": ["MEDIUM", "HIGH"],
                }
            },
        },
    }
    result = await client.execute(rule_query, variable_values=rule_variables)
    assert not result["notificationRuleCreate"]["errors"]

    print("Created channel and rule successfully")
```
