Developers · · Updated

How to Get a Slack Bot Token (Step-by-Step)

Akshat Jain
10 min read
Table of Contents

To get a Slack bot token, create an app from scratch at api.slack.com/apps. Open the OAuth & Permissions sidebar to add the Bot Token Scopes your integration needs, such as chat:write. Click Install to Workspace, approve the permissions on the consent screen, and copy the Bot User OAuth Token, which starts with xoxb-. Pass that token in the Authorization: Bearer header to call Slack’s Web API at the https://slack.com/api/ base URL.

Key Takeaways

  • Create an app and copy the xoxb- token directly from the OAuth & Permissions menu.
  • Reinstall the app whenever you add a new scope, so the install grants it.
  • Rely on token rotation to enforce a 12-hour expiration cycle, since bot tokens do not expire by default.
  • Store credentials securely in a local file like credentials.json or an environment variable instead of hard-coding them.

Prerequisites

You need a Slack workspace where you can install apps, or an admin who can approve the install. You also need to know which Bot Token Scopes your integration requires upfront. Scopes are the permissions your Slack app requests to act. Each scope grants access to a specific set of actions or data, such as reading messages in a channel or viewing a user’s profile, according to Slack’s scopes documentation.

Scopes added after install take effect only when you reinstall the app. Each installation adds to the scopes you have already been granted, and there is no way to remove a scope from an existing token without revoking it, according to Slack’s OAuth installation docs. This means planning your integration’s required permissions ahead of time saves redundant configuration cycles.

If your integration needs to act as a specific person rather than a bot, you need a user token (xoxp-) instead. Read our guide on integrating with the Slack API to learn which API surface fits your specific use case. Bot tokens represent the application itself, while user tokens inherit the authorization level of the human who installs them.

Token Type Prefix Best For
Bot Token xoxb- Workspace-level app actions
User Token xoxp- Acting as a specific human user

Where the credential goes

Slack’s Web API accepts the token as a bearer token in the Authorization header. The setup relies on HTTP methods that retrieve the OAuth access token and automatically add it as a Bearer token in the outgoing API requests.

The exact format required is Authorization: Bearer xoxb-.... The word Bearer is case-sensitive and must match exactly for the server to recognize the credentials. For some POST endpoints, you can send the token as a token= form field with the Content-Type: application/x-www-form-urlencoded header.

Adding a new Bot Token Scope later does not take effect on its own. You must reinstall the app before the scope works. A token is revoked when you call the auth.revoke method or uninstall the app from the workspace, according to Slack’s OAuth installation docs.

Bot tokens (xoxb-) remain valid until revoked or uninstalled, unless token rotation is enabled. Slack’s authentication documentation states that without token rotation, the access token never expires. With token rotation, it expires every 12 hours.

Refresh tokens are designed to be used once. After calling the OAuth access API method, the refresh token you used is revoked after a short grace period.

Storing the Slack Bot Token

Knowing where to find your token strings is only the first step. If you want to know how to manage access for automated scripts without exposing keys, environment variables are the standard approach. Never hard-code the SLACK_BOT_TOKEN directly into your application source code. Committing tokens to source control exposes your workspace to unauthorized access and requires immediate revocation.

To store the token locally during testing, save a slack_bot_token credentials.json file in your project directory and parse it using your programming language’s standard JSON library. Make sure to add this file to your version control ignore rules so it stays local. Alternatively, you can store the slack_bot_token config.ini under a specific profile block. Load it via an environment configuration manager to keep the credential out of your version control history. Secure token storage protects your integration from unauthorized data access.

Find technical guides and code samples for developers building integrations in our developer tutorials collection. Managing credentials securely is a universal requirement, whether you are generating a Slack token or figuring out how to generate a Jira API token.

If you need a user token or a multi-workspace OAuth flow

For apps installed by many different workspaces, setup is performed via an OAuth2 redirection flow. There are no manually configured parameters for the user to enter directly into your application. Send users to the authorization URL, constructed with your client_id, requested scopes, and a specific redirect_uri. The base URL for API calls is hardcoded and set to https://slack.com/api/.

Slack redirects back with a temporary code that you exchange at the oauth.v2.access endpoint for an access token. This approach scales across multiple organizations without requiring manual dashboard access for every single workspace. The process guarantees that users authorize exactly the permissions they understand. You can apply similar token management strategies when you learn how to request a Zendesk API token.

Minimal working example

Testing the authentication confirms the token is valid and returns basic identity info as a smoke test. This step verifies your configuration before you write business logic. Store SLACK_BOT_TOKEN as an environment variable before running these scripts. The examples below demonstrate how to format the authentication header correctly.

Example using curl with the Authorization: Bearer header:

curl -X POST https://slack.com/api/auth.test \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json"

Example using Node.js fetch with the Authorization: Bearer header:

const res = await fetch("https://slack.com/api/auth.test", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SLACK_BOT_TOKEN}`,
    "Content-Type": "application/json"
  },
});
const data = await res.json();
console.log(data);

Common errors and fixes

Invalid authentication (invalid_auth)

An invalid_auth error means the token is missing, malformed, or has been revoked. Check that the header reads Authorization: Bearer xoxb-... with no extra quotation marks. Confirm the app is still installed to the workspace under OAuth & Permissions.

Missing permissions (missing_scope)

A missing_scope error means you need to add the required scope under OAuth & Permissions and reinstall the app so the install grants it. The response body includes needed and provided fields showing exactly which scope is required and which scopes your token actually has. A common trigger for this error occurs when developers add the scope in the dashboard, but never reinstall the app. Adding the scope in the dashboard alone is not enough.

Handling rate limits

You exceed the Slack Web API per-method rate limit tiers for your app in this workspace when this error occurs. Slack returns a 429 status code with a Retry-After header telling you how many seconds to wait before retrying. Implement exponential backoff to handle these responses automatically.

The faster way with Knit

Managing Slack app installs, scope changes, and rate limits gets harder when supporting many workspaces. Each workspace operates with its own installed scopes, token lifecycles, and rate-limit tiers on top of whatever other communication tools you connect. You can create your own Slack Bot with the Knit Unified API. Read this step-by-step tutorial on building a custom Slack Bot integration.

Use Knit’s Client OAuth Credentials API to share your Bot credentials with Knit for Slack. According to Knit’s Client OAuth Credentials API documentation, this API is currently supported for Microsoft Teams and Slack. Knit handles the OAuth installs and token storage across connectors for you.

With Knit: Knit normalizes these token requirements across providers so you pass consistent credentials, and handles token rotation automatically for connected workspaces.

The Slack API integration module connects via Knit’s Unified Communication API for one integration schema. You can also give your AI agent access to every Communication platform Knit supports using real, already-built communication MCP server categories.

For example, you can register a bot command using Knit’s bot command registration endpoint. The API requires your base URL, authorization header, integration ID, and JSON payload parameters.

curl -X POST "https://api.getknit.dev/v1.0/comm.bot.registerCommand?commandType=slash" \
  -H "Authorization: Bearer <YOUR_KNIT_API_KEY>" \
  -H "X-Knit-Integration-Id: <integration-id>" \
  -H "Content-Type: application/json" \
  -d '{"appId": "slack", "keyCommand": "start", "argumentCommand": "help", "destination": "channel"}'

Frequently Asked Questions

Where do I find my Slack bot token after creating it?

You find the token on the OAuth & Permissions page after clicking Install to Workspace. Slack shows the Bot User OAuth Token, starting with xoxb-. You can return to this page any time to copy it again. Slack does not hide it after the first view, but you should still store it as a secret inside an environment variable.

What’s the difference between a bot token (xoxb-) and a user token (xoxp-)?

A bot token (xoxb-) belongs to the app itself and is shared across the workspace install. A user token (xoxp-) acts on behalf of a specific person with that person’s own permissions. Use a bot token unless your integration specifically needs to act as a particular human user. An app-level token (xapp-) represents your app across organizations and is used for Socket Mode connections.

Do Slack bot tokens expire?

Slack bot tokens do not expire by default. They remain valid until revoked or until the app is uninstalled from the workspace. If token rotation is enabled, the access token expires every 12 hours. The rotation system issues a refresh token to request a new access token automatically.

Why is my newly added scope not working?

Adding a Bot Token Scope in your app settings is not enough on its own. A newly added scope does not work until you reinstall the app to the workspace, because each installation is what grants scopes, and new ones are added to those already granted. This fixes missing scope errors after a configuration change.

Is the Slack API free to use with a bot token?

Creating an app, installing it, and calling the Web API is free. Usage is governed by per-method rate limit tiers, and some methods have additional limits for newer apps.

What’s the difference between Slack bot and app tokens?

A bot token (xoxb-) belongs to the installed app and handles standard Web API requests for reading and writing data. An app-level token (xapp-) represents your app across organizations rather than one workspace. Its main use is Socket Mode: your app uses it to generate a WebSocket URL, and Slack sends events over that connection instead of to a public endpoint, according to Slack’s Socket Mode docs. You generate app-level tokens under Basic Information in your app settings.

How do I find my Slack Client ID and Client Secret?

Your app’s Client ID is on its App Management page at api.slack.com/apps, according to Slack’s OAuth installation docs. The Client Secret is in the same app admin panel, where a Regenerate button lets you replace it if it leaks. These credentials authorize the OAuth flow for public applications. You must treat the Client Secret as highly sensitive and never expose it in client-side code.

Written by Akshat Jain

Coding chaos into innovation and building from zero to scale

Keep Reading

#1 in Ease of Integrations

4.9 out of 5 stars

4.9 out of 5 stars on G2

G2 Leader, Spring 2026G2 Fastest Implementation, Spring 2026G2 High Performer, Spring 2026G2 Best Est. ROI, Spring 2026

Put Integrations on Autopilot. Talk to Experts.

Knit is loved by customers across the globe due to our seamless product and white glove support. You'll love us too!

Talk to a Human