Slack API
Use this page for Slack-only public V2 endpoints.
Authentication
All Slack V2 public endpoints require:
x-api-keyx-api-secretContent-Type: application/json
Base path:
/v2
Rate limit:
180 requests / 60 seconds
Slack Routes
| Method | Path | Purpose |
|---|---|---|
POST | /v2/slack/send | Send a new Slack message |
POST | /v2/slack/reply | Reply to an existing Slack message |
Send A Slack Message
POST /v2/slack/send
Required Fields
channelmessage
Optional Fields
replyTo
- cURL
- Node
- Python
- Go
- Java
- PHP
- C#
- Rust
- C++
- Elixir
curl --request POST \
--url https://api.usealerta.com/v2/slack/send \
--header "content-type: application/json" \
--header "x-api-key: YOUR_API_KEY" \
--header "x-api-secret: YOUR_API_SECRET" \
--data '{
"channel": "alerts",
"message": "Database replication lag exceeded threshold.",
"replyTo": false
}'
const response = await fetch("https://api.usealerta.com/v2/slack/send", {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": process.env.ALERTA_API_KEY,
"x-api-secret": process.env.ALERTA_API_SECRET,
},
body: JSON.stringify({
channel: "alerts",
message: "Database replication lag exceeded threshold.",
replyTo: false,
}),
});
const data = await response.json();
console.log(data);
import os
import requests
response = requests.post(
"https://api.usealerta.com/v2/slack/send",
headers={
"content-type": "application/json",
"x-api-key": os.environ["ALERTA_API_KEY"],
"x-api-secret": os.environ["ALERTA_API_SECRET"],
},
json={
"channel": "alerts",
"message": "Database replication lag exceeded threshold.",
"replyTo": False,
},
timeout=30,
)
print(response.json())
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload := []byte(`{
"channel": "alerts",
"message": "Database replication lag exceeded threshold.",
"replyTo": false
}`)
req, err := http.NewRequest(http.MethodPost, "https://api.usealerta.com/v2/slack/send", bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
req.Header.Set("content-type", "application/json")
req.Header.Set("x-api-key", os.Getenv("ALERTA_API_KEY"))
req.Header.Set("x-api-secret", os.Getenv("ALERTA_API_SECRET"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public final class SendSlackMessage {
public static void main(String[] args) throws Exception {
String payload = """
{
"channel": "alerts",
"message": "Database replication lag exceeded threshold.",
"replyTo": false
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.usealerta.com/v2/slack/send"))
.header("content-type", "application/json")
.header("x-api-key", System.getenv("ALERTA_API_KEY"))
.header("x-api-secret", System.getenv("ALERTA_API_SECRET"))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$payload = [
"channel" => "alerts",
"message" => "Database replication lag exceeded threshold.",
"replyTo" => false,
];
$ch = curl_init("https://api.usealerta.com/v2/slack/send");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"content-type: application/json",
"x-api-key: " . getenv("ALERTA_API_KEY"),
"x-api-secret: " . getenv("ALERTA_API_SECRET"),
],
CURLOPT_POSTFIELDS => json_encode($payload, JSON_THROW_ON_ERROR),
CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch) . PHP_EOL;
curl_close($ch);
using System.Net.Http.Headers;
using System.Text;
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", Environment.GetEnvironmentVariable("ALERTA_API_KEY"));
client.DefaultRequestHeaders.Add("x-api-secret", Environment.GetEnvironmentVariable("ALERTA_API_SECRET"));
var json = """
{
"channel": "alerts",
"message": "Database replication lag exceeded threshold.",
"replyTo": false
}
""";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.usealerta.com/v2/slack/send", content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use serde_json::json;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
headers.insert("x-api-key", HeaderValue::from_str(&env::var("ALERTA_API_KEY")?)?);
headers.insert("x-api-secret", HeaderValue::from_str(&env::var("ALERTA_API_SECRET")?)?);
let payload = json!({
"channel": "alerts",
"message": "Database replication lag exceeded threshold.",
"replyTo": false
});
let response = reqwest::Client::new()
.post("https://api.usealerta.com/v2/slack/send")
.headers(headers)
.json(&payload)
.send()
.await?
.text()
.await?;
println!("{response}");
Ok(())
}
#include <curl/curl.h>
int main() {
CURL *curl = curl_easy_init();
if (!curl) return 1;
struct curl_slist *headers = nullptr;
headers = curl_slist_append(headers, "content-type: application/json");
headers = curl_slist_append(headers, "x-api-key: YOUR_API_KEY");
headers = curl_slist_append(headers, "x-api-secret: YOUR_API_SECRET");
const char *payload =
"{\"channel\":\"alerts\",\"message\":\"Database replication lag exceeded threshold.\",\"replyTo\":false}";
curl_easy_setopt(curl, CURLOPT_URL, "https://api.usealerta.com/v2/slack/send");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);
curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return 0;
}
url = "https://api.usealerta.com/v2/slack/send"
headers = [
{"content-type", "application/json"},
{"x-api-key", System.fetch_env!("ALERTA_API_KEY")},
{"x-api-secret", System.fetch_env!("ALERTA_API_SECRET")}
]
body =
Jason.encode!(%{
channel: "alerts",
message: "Database replication lag exceeded threshold.",
replyTo: false
})
{:ok, response} = Req.post(url, headers: headers, body: body)
IO.puts(response.body)
Sample Response
{
"statusCode": 200,
"message": "Message sent successfully",
"data": {
"replyData": ""
}
}
If replyTo: true, the response may include:
{
"statusCode": 200,
"message": "Message sent successfully",
"data": {
"replyData": {
"channelId": "C123",
"threadId": "1712345678.123456",
"channelRef": "CHANREF-11"
}
}
}
Reply To A Slack Message
POST /v2/slack/reply
Required Fields
channelRefchannelIdthreadIdmessage
- cURL
- Node
- Python
- Go
- Java
- PHP
- C#
- Rust
- C++
- Elixir
curl --request POST \
--url https://api.usealerta.com/v2/slack/reply \
--header "content-type: application/json" \
--header "x-api-key: YOUR_API_KEY" \
--header "x-api-secret: YOUR_API_SECRET" \
--data '{
"channelRef": "CHANREF-11",
"channelId": "C123",
"threadId": "1712345678.123456",
"message": "Acknowledged, investigating now."
}'
const response = await fetch("https://api.usealerta.com/v2/slack/reply", {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": process.env.ALERTA_API_KEY,
"x-api-secret": process.env.ALERTA_API_SECRET,
},
body: JSON.stringify({
channelRef: "CHANREF-11",
channelId: "C123",
threadId: "1712345678.123456",
message: "Acknowledged, investigating now.",
}),
});
const data = await response.json();
console.log(data);
import os
import requests
response = requests.post(
"https://api.usealerta.com/v2/slack/reply",
headers={
"content-type": "application/json",
"x-api-key": os.environ["ALERTA_API_KEY"],
"x-api-secret": os.environ["ALERTA_API_SECRET"],
},
json={
"channelRef": "CHANREF-11",
"channelId": "C123",
"threadId": "1712345678.123456",
"message": "Acknowledged, investigating now.",
},
timeout=30,
)
print(response.json())
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload := []byte(`{
"channelRef": "CHANREF-11",
"channelId": "C123",
"threadId": "1712345678.123456",
"message": "Acknowledged, investigating now."
}`)
req, err := http.NewRequest(http.MethodPost, "https://api.usealerta.com/v2/slack/reply", bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
req.Header.Set("content-type", "application/json")
req.Header.Set("x-api-key", os.Getenv("ALERTA_API_KEY"))
req.Header.Set("x-api-secret", os.Getenv("ALERTA_API_SECRET"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public final class ReplySlackMessage {
public static void main(String[] args) throws Exception {
String payload = """
{
"channelRef": "CHANREF-11",
"channelId": "C123",
"threadId": "1712345678.123456",
"message": "Acknowledged, investigating now."
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.usealerta.com/v2/slack/reply"))
.header("content-type", "application/json")
.header("x-api-key", System.getenv("ALERTA_API_KEY"))
.header("x-api-secret", System.getenv("ALERTA_API_SECRET"))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$payload = [
"channelRef" => "CHANREF-11",
"channelId" => "C123",
"threadId" => "1712345678.123456",
"message" => "Acknowledged, investigating now.",
];
$ch = curl_init("https://api.usealerta.com/v2/slack/reply");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"content-type: application/json",
"x-api-key: " . getenv("ALERTA_API_KEY"),
"x-api-secret: " . getenv("ALERTA_API_SECRET"),
],
CURLOPT_POSTFIELDS => json_encode($payload, JSON_THROW_ON_ERROR),
CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch) . PHP_EOL;
curl_close($ch);
using System.Text;
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", Environment.GetEnvironmentVariable("ALERTA_API_KEY"));
client.DefaultRequestHeaders.Add("x-api-secret", Environment.GetEnvironmentVariable("ALERTA_API_SECRET"));
var json = """
{
"channelRef": "CHANREF-11",
"channelId": "C123",
"threadId": "1712345678.123456",
"message": "Acknowledged, investigating now."
}
""";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.usealerta.com/v2/slack/reply", content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use serde_json::json;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
headers.insert("x-api-key", HeaderValue::from_str(&env::var("ALERTA_API_KEY")?)?);
headers.insert("x-api-secret", HeaderValue::from_str(&env::var("ALERTA_API_SECRET")?)?);
let payload = json!({
"channelRef": "CHANREF-11",
"channelId": "C123",
"threadId": "1712345678.123456",
"message": "Acknowledged, investigating now."
});
let response = reqwest::Client::new()
.post("https://api.usealerta.com/v2/slack/reply")
.headers(headers)
.json(&payload)
.send()
.await?
.text()
.await?;
println!("{response}");
Ok(())
}
#include <curl/curl.h>
int main() {
CURL *curl = curl_easy_init();
if (!curl) return 1;
struct curl_slist *headers = nullptr;
headers = curl_slist_append(headers, "content-type: application/json");
headers = curl_slist_append(headers, "x-api-key: YOUR_API_KEY");
headers = curl_slist_append(headers, "x-api-secret: YOUR_API_SECRET");
const char *payload =
"{\"channelRef\":\"CHANREF-11\",\"channelId\":\"C123\",\"threadId\":\"1712345678.123456\",\"message\":\"Acknowledged, investigating now.\"}";
curl_easy_setopt(curl, CURLOPT_URL, "https://api.usealerta.com/v2/slack/reply");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);
curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return 0;
}
url = "https://api.usealerta.com/v2/slack/reply"
headers = [
{"content-type", "application/json"},
{"x-api-key", System.fetch_env!("ALERTA_API_KEY")},
{"x-api-secret", System.fetch_env!("ALERTA_API_SECRET")}
]
body =
Jason.encode!(%{
channelRef: "CHANREF-11",
channelId: "C123",
threadId: "1712345678.123456",
message: "Acknowledged, investigating now."
})
{:ok, response} = Req.post(url, headers: headers, body: body)
IO.puts(response.body)
Sample Response
{
"statusCode": 200,
"message": "Reply sent successfully",
"data": {
"balance": 90
}
}
Common Errors
{
"statusCode": 403,
"message": "Missing API key"
}
{
"statusCode": 403,
"message": "Missing API secret"
}
{
"statusCode": 403,
"message": "Invalid API key"
}
{
"statusCode": 403,
"message": "Invalid API secret"
}
{
"statusCode": 403,
"message": "Organization is inactive"
}
{
"statusCode": 400,
"message": "Invalid Channel reference"
}
Slack Notes
- Slack
senduses the configured Slackchannelname. - Slack
replyuseschannelRef,channelId, andthreadId. channelRefis an internal Alerta reference, not the Slack channel name or ID.