> ## Documentation Index
> Fetch the complete documentation index at: https://docs.braintrust.dev/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".

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Any
> *
> * Use case - Programmatically create Slack alerts for a project using the project\_automation API

## 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 ** Settings** > [** Alerts**](https://www.braintrust.dev/app/~/configuration/automations/alerts).
2. Click  **Alert**, or  **Create alert** if you don't have any alerts yet, 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](https://docs.braintrust.dev/admin/automations/alerts.md). For the API schema, see [Create project automation](https://docs.braintrust.dev/api-reference/projectautomations/create-project-automation.md).
* `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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.