How to hit the Slack API

Slack's Web API is a set of methods at https://slack.com/api/<method>. It answers HTTP 200 even on failure — check the ok field and read error when it's false.

Authentication

Create an app at api.slack.com/apps, add bot scopes (chat:write, channels:read, channels:history), install it to your workspace, and copy the xoxb-… bot token. Send it as Authorization: Bearer <token>. In the examples it's written {{SLACK_BOT_TOKEN}}.

Full reference: https://docs.slack.dev/apis/web-api/

Test a token

Returns the workspace, bot user, and team id the token belongs to.

curl -X POST https://slack.com/api/auth.test \
  -H "Authorization: Bearer {{SLACK_BOT_TOKEN}}"
Run in PostTaco

Post a message

The bot must be in the channel. channel takes a channel id (C…).

curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer {{SLACK_BOT_TOKEN}}" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"channel": "{{CHANNEL_ID}}", "text": "Hello from PostTaco :taco:"}'
Run in PostTaco

List channels

Public channels with their ids. Page with cursor from response_metadata.next_cursor.

curl "https://slack.com/api/conversations.list?types=public_channel&limit=20" \
  -H "Authorization: Bearer {{SLACK_BOT_TOKEN}}"
Run in PostTaco

Read channel history

Most recent messages first.

curl "https://slack.com/api/conversations.history?channel={{CHANNEL_ID}}&limit=10" \
  -H "Authorization: Bearer {{SLACK_BOT_TOKEN}}"
Run in PostTaco

Send an incoming webhook

No token — the webhook URL is the secret. Create one under your app's Incoming Webhooks; paste the part after /services/.

curl -X POST https://hooks.slack.com/services/{{SLACK_WEBHOOK_PATH}} \
  -H "Content-Type: application/json" \
  -d '{"text": "Deploy finished :white_check_mark:"}'
Run in PostTaco