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

# Create Slack alerts via the project_automation API

> Programmatically create Slack alerts for a project using the project_automation API with a POST request and action type "slack".

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = "Use case - Programmatically create Slack alerts for a project using the project_automation API"

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## Summary

Slack alerts can be created programmatically with the Project automation API. Create a `project_automation` where `config.event_type` is `"logs"` and `config.action.type` is `"slack"`, then set `workspace_id` and `channel` to the Slack workspace and channel IDs. Ensure the Slack integration is enabled and the API key can create project automations.

## What is happening

The UI exposes Slack alert setup but the same behavior can be reproduced via the project\_automation API. When you `POST` to `/v1/project_automation` with an action of type `"slack"`, the platform sends alerts to the specified Slack workspace and channel. If the workspace app is not installed or the bot lacks channel write permissions, messages will not arrive.

## Fix or suggestion

### Option 1: Create Slack alerts via the API (recommended)

1. Ensure the Slack integration/app is installed in the target workspace and the bot can post to the channel.
2. Use an API key with permission to create project automations.
3. `POST` a `project_automation` with a `config` that includes `event_type`, `btql_filter`, `interval_seconds`, and an `action` of type `"slack"`. Example minimal payload:

```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
# US hosted: https://api.braintrust.dev
# EU hosted: https://api-eu.braintrust.dev
# Self-hosted: your data-plane API URL
export BRAINTRUST_API_URL="https://api.braintrust.dev"
curl --request POST \
  --url "$BRAINTRUST_API_URL/v1/project_automation" \
  --header "Authorization: Bearer $BRAINTRUST_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "project_id": "PROJECT_ID",
    "name": "Production error Slack alert",
    "description": "Notify Slack when production logs contain errors",
    "config": {
      "event_type": "logs",
      "btql_filter": "error IS NOT NULL AND metadata.environment = '\''production'\''",
      "interval_seconds": 300,
      "action": {
        "type": "slack",
        "workspace_id": "SLACK_WORKSPACE_ID",
        "channel": "SLACK_CHANNEL_ID"
      }
    }
  }'
```

Notes:

* Use Slack workspace and channel IDs, such as `T...` and `C...`. The `channel` field is the Slack channel ID, not the channel name.
* Ensure the Slack app has the scopes required to post messages to the target channel.

### Option 2: Configure Slack alerts via the UI

1. Go to **<Icon icon="settings-2" /> Settings** > [**<Icon icon="bell" /> Alerts**](https://www.braintrust.dev/app/~/configuration/alerts).
2. Click <Icon icon="plus" /> **New alert** and select **Slack** as the destination.
3. Select the workspace and channel from the dropdowns.

Use the UI if you prefer interactive workspace/channel selection or if you need the platform to refresh channel lists automatically.

## How to confirm it worked

* Verify the automation appears in the project's automations list in the UI.
* Trigger a test event matching your filter and confirm a message appears in the specified Slack channel.

## Notes

* For UI setup, see [Alerts](/admin/automations/alerts). For the API schema, see [Create project automation](/api-reference/projectautomations/create-project_automation).
* `POST /v1/project_automation` returns an existing automation unchanged when another automation with the same name already exists. Use `PUT /v1/project_automation` if you need create-or-replace behavior.
* For self-hosted deployments, alerts require data plane v0.0.72 or later, and Slack alerts require data plane v1.1.29 or later.
